diff --git a/lib/paperclip/storage/fog.rb b/lib/paperclip/storage/fog.rb index 1a89d7a68..b25bd166e 100644 --- a/lib/paperclip/storage/fog.rb +++ b/lib/paperclip/storage/fog.rb @@ -214,17 +214,9 @@ def host_name_for_directory def find_credentials(creds) case creds when File - if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0") - YAML::safe_load(ERB.new(File.read(creds.path)).result, aliases: true) - else - YAML::safe_load(ERB.new(File.read(creds.path)).result) - end + load_credentials_from_file(creds.path) when String, Pathname - if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0") - YAML::safe_load(ERB.new(File.read(creds)).result, aliases: true) - else - YAML::safe_load(ERB.new(File.read(creds)).result) - end + load_credentials_from_file(creds.path) when Hash creds else @@ -236,6 +228,14 @@ def find_credentials(creds) end end + def load_credentials_from_file(path) + if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0") + YAML::safe_load(ERB.new(File.read(path)).result, aliases: true) + else + YAML::safe_load(ERB.new(File.read(path)).result, [], [], true) + end + end + def connection @connection ||= ::Fog::Storage.new(fog_credentials) end diff --git a/lib/paperclip/storage/s3.rb b/lib/paperclip/storage/s3.rb index f06cffcfa..37eee5777 100644 --- a/lib/paperclip/storage/s3.rb +++ b/lib/paperclip/storage/s3.rb @@ -1,3 +1,4 @@ +# coding: utf-8 module Paperclip module Storage # Amazon's S3 file hosting service is a scalable, easy place to store files for @@ -433,17 +434,9 @@ def copy_to_local_file(style, local_dest_path) def find_credentials(creds) case creds when File - if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0") - YAML::safe_load(ERB.new(File.read(creds.path)).result, aliases: true) - else - YAML::safe_load(ERB.new(File.read(creds.path)).result) - end + load_credentials_from_file(creds.path) when String, Pathname - if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0") - YAML::safe_load(ERB.new(File.read(creds)).result, aliases: true) - else - YAML::safe_load(ERB.new(File.read(creds)).result) - end + load_credentials_from_file(creds) when Hash creds when NilClass