From ee3232f1c2138e1425f6da605afa5fc32895abe8 Mon Sep 17 00:00:00 2001 From: Surendra Singhi Date: Wed, 7 Aug 2024 16:24:06 +0530 Subject: [PATCH] cleanup code from PR #135 --- lib/paperclip/storage/fog.rb | 20 ++++++++++---------- lib/paperclip/storage/s3.rb | 13 +++---------- 2 files changed, 13 insertions(+), 20 deletions(-) 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