From 48c81bc6e34f2f095cb3cca2267e2d27b4a834d8 Mon Sep 17 00:00:00 2001 From: chris Date: Fri, 5 Apr 2013 16:17:12 +1100 Subject: [PATCH] Allow the use of fog options from .fog file ie. remove all the validations and just let fog worry about it (which BTW it does) --- lib/asset_sync/config.rb | 43 +++++++++++++++------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/lib/asset_sync/config.rb b/lib/asset_sync/config.rb index aa976020..0bab39d2 100644 --- a/lib/asset_sync/config.rb +++ b/lib/asset_sync/config.rb @@ -36,13 +36,6 @@ class Invalid < StandardError; end validates :fog_provider, :presence => true validates :fog_directory, :presence => true - validates :aws_access_key_id, :presence => true, :if => :aws? - validates :aws_secret_access_key, :presence => true, :if => :aws? - validates :rackspace_username, :presence => true, :if => :rackspace? - validates :rackspace_api_key, :presence => true, :if => :rackspace? - validates :google_storage_secret_access_key, :presence => true, :if => :google? - validates :google_storage_access_key_id, :presence => true, :if => :google? - def initialize self.fog_region = nil self.existing_remote_files = 'keep' @@ -155,35 +148,31 @@ def load_yml! self.fog_region = yml["region"] if yml.has_key?("region") end - def fog_options - options = { :provider => fog_provider } + { :provider => fog_provider }.tap { |options| + fog_option_keys.each do |key| + val = send(key) + options[key] = val unless val.blank? + end + + options[:region] = fog_region if fog_region + } + end + + private + + def fog_option_keys if aws? - options.merge!({ - :aws_access_key_id => aws_access_key_id, - :aws_secret_access_key => aws_secret_access_key - }) + [:aws_access_key_id, :aws_secret_access_key] elsif rackspace? - options.merge!({ - :rackspace_username => rackspace_username, - :rackspace_api_key => rackspace_api_key - }) - options.merge!({ :rackspace_auth_url => rackspace_auth_url }) if rackspace_auth_url + [:rackspace_username, :rackspace_api_key, :rackspace_auth_url] elsif google? - options.merge!({ - :google_storage_secret_access_key => google_storage_secret_access_key, - :google_storage_access_key_id => google_storage_access_key_id - }) + [:google_storage_secret_access_key, :google_storage_access_key_id] else raise ArgumentError, "AssetSync Unknown provider: #{fog_provider} only AWS and Rackspace are supported currently." end - - options.merge!({:region => fog_region}) if fog_region - return options end - private - def default_manifest_directory File.join(Rails.public_path, assets_prefix) end