Commit 50b68fc2 authored by Shinya Maeda's avatar Shinya Maeda

Use prepend to correctly use the monketpatch's method

parent b358d263
...@@ -5,36 +5,40 @@ module CarrierWave ...@@ -5,36 +5,40 @@ module CarrierWave
module Storage module Storage
class Fog < Abstract class Fog < Abstract
class File class File
def read module MonkeyPatch
file_body = file.body def read
file_body = file.body
return if file_body.nil? return if file_body.nil?
return file_body unless file_body.is_a?(::File) return file_body unless file_body.is_a?(::File)
begin begin
file_body = ::File.open(file_body.path) if file_body.closed? # Reopen if it's closed file_body = ::File.open(file_body.path) if file_body.closed? # Reopen if it's closed
file_body.read file_body.read
ensure ensure
file_body.close file_body.close
end
end end
end
def store(new_file) def store(new_file)
if new_file.is_a?(self.class) # rubocop:disable Gitlab/LineBreakAroundConditionalBlock if new_file.is_a?(self.class) # rubocop:disable Gitlab/LineBreakAroundConditionalBlock
new_file.copy_to(path) new_file.copy_to(path)
else else
fog_file = new_file.to_file fog_file = new_file.to_file
@content_type ||= new_file.content_type @content_type ||= new_file.content_type # rubocop:disable Gitlab/ModuleWithInstanceVariables
@file = directory.files.create({ @file = directory.files.create({ # rubocop:disable Gitlab/ModuleWithInstanceVariables
:body => fog_file ? fog_file : new_file.read, # rubocop:disable Gitlab/HashSyntax :body => fog_file ? fog_file : new_file.read, # rubocop:disable Gitlab/HashSyntax
:content_type => @content_type, # rubocop:disable Gitlab/HashSyntax :content_type => @content_type, # rubocop:disable Gitlab/HashSyntax,Gitlab/ModuleWithInstanceVariables
:key => path, # rubocop:disable Gitlab/HashSyntax :key => path, # rubocop:disable Gitlab/HashSyntax
:public => @uploader.fog_public # rubocop:disable Gitlab/HashSyntax :public => @uploader.fog_public # rubocop:disable Gitlab/HashSyntax,Gitlab/ModuleWithInstanceVariables
}.merge(@uploader.fog_attributes)) }.merge(@uploader.fog_attributes)) # rubocop:disable Gitlab/ModuleWithInstanceVariables
fog_file.close if fog_file && !fog_file.closed? fog_file.close if fog_file && !fog_file.closed?
end
true
end end
true
end end
prepend MonkeyPatch
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment