diff options
-rw-r--r-- | config/initializers/carrierwave_monkey_patch.rb | 52 |
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 |