summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-05-25 14:31:11 +0900
committerShinya Maeda <shinya@gitlab.com>2018-05-28 14:34:37 +0900
commit50b68fc2ea8c0428142c96378422a3138dbf0fe1 (patch)
tree909d189bc5d1049a6dcd61dde40ba9cc6c10c2d0
parentb358d263ce05483b565f5a41e0597fe6371a8782 (diff)
downloadgitlab-ce-50b68fc2ea8c0428142c96378422a3138dbf0fe1.tar.gz
Use prepend to correctly use the monketpatch's method
-rw-r--r--config/initializers/carrierwave_monkey_patch.rb52
1 files changed, 28 insertions, 24 deletions
diff --git a/config/initializers/carrierwave_monkey_patch.rb b/config/initializers/carrierwave_monkey_patch.rb
index d81e5607b45..dd2c656b171 100644
--- a/config/initializers/carrierwave_monkey_patch.rb
+++ b/config/initializers/carrierwave_monkey_patch.rb
@@ -5,36 +5,40 @@ module CarrierWave
module Storage
class Fog < Abstract
class File
- def read
- file_body = file.body
+ module MonkeyPatch
+ def read
+ file_body = file.body
- return if file_body.nil?
- return file_body unless file_body.is_a?(::File)
+ return if file_body.nil?
+ return file_body unless file_body.is_a?(::File)
- begin
- file_body = ::File.open(file_body.path) if file_body.closed? # Reopen if it's closed
- file_body.read
- ensure
- file_body.close
+ begin
+ file_body = ::File.open(file_body.path) if file_body.closed? # Reopen if it's closed
+ file_body.read
+ ensure
+ file_body.close
+ end
end
- end
- def store(new_file)
- if new_file.is_a?(self.class) # rubocop:disable Gitlab/LineBreakAroundConditionalBlock
- new_file.copy_to(path)
- else
- fog_file = new_file.to_file
- @content_type ||= new_file.content_type
- @file = directory.files.create({
- :body => fog_file ? fog_file : new_file.read, # rubocop:disable Gitlab/HashSyntax
- :content_type => @content_type, # rubocop:disable Gitlab/HashSyntax
- :key => path, # rubocop:disable Gitlab/HashSyntax
- :public => @uploader.fog_public # rubocop:disable Gitlab/HashSyntax
- }.merge(@uploader.fog_attributes))
- fog_file.close if fog_file && !fog_file.closed?
+ def store(new_file)
+ if new_file.is_a?(self.class) # rubocop:disable Gitlab/LineBreakAroundConditionalBlock
+ new_file.copy_to(path)
+ else
+ fog_file = new_file.to_file
+ @content_type ||= new_file.content_type # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ @file = directory.files.create({ # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ :body => fog_file ? fog_file : new_file.read, # rubocop:disable Gitlab/HashSyntax
+ :content_type => @content_type, # rubocop:disable Gitlab/HashSyntax,Gitlab/ModuleWithInstanceVariables
+ :key => path, # rubocop:disable Gitlab/HashSyntax
+ :public => @uploader.fog_public # rubocop:disable Gitlab/HashSyntax,Gitlab/ModuleWithInstanceVariables
+ }.merge(@uploader.fog_attributes)) # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ fog_file.close if fog_file && !fog_file.closed?
+ end
+ true
end
- true
end
+
+ prepend MonkeyPatch
end
end
end