lib/capistrano/recipes/uploader.rb in marcosgz-cap-recipe-0.0.8 vs lib/capistrano/recipes/uploader.rb in marcosgz-cap-recipe-0.0.9

- old
+ new

@@ -1,36 +1,43 @@ -# Example -# ======= -# -# uploader_setup_settings: -# fog_credentials: -# provider: Rackspace -# rackspace_username: username -# rackspace_api_key: secret -# fog_directory: frontend -# fog_host: http://123.rackcdn.com - Capistrano::Configuration.instance(:must_exist).load do - set(:uploader_remote_file) { File.join(shared_path, 'config/uploader.yml') } unless exists?(:uploader_remote_file) - set(:uploader_template, 'uploader.yml.erb') unless exists?(:uploader_template) - namespace :uploader do namespace :setup do desc "Upload configs" task :default, :roles => :app do if exists?(:uploader_setup_settings) - set :recipe_settings, fetch(:uploader_setup_settings, {}) - put template.render(fetch(:uploader_template)), fetch(:uploader_remote_file) + set(:recipe_settings) { uploader_template_settings } + put template.render(_uploader_template), _uploader_remote_file else puts "[FATAL] - Uploader template settings were not found" abort end end desc "Download configs" task :get, :roles => :db do - download fetch(:uploader_remote_file), File.join(local_rails_root, "config/uploader.yml") + download _uploader_remote_file, _uploader_local_file end end end + + def uploader_setup_defaults + HashWithIndifferentAccess.new({'common'=>{}}.reverse_merge(default_rails_environments_hash)) + end + + def uploader_template_settings + DeepToHash.to_hash uploader_setup_defaults.deep_merge(fetch(:uploader_setup_settings, {})) + end + + def _uploader_remote_file + File.join(shared_path, fetch(:uploader_remote_file, 'config/uploader.yml')) + end + + def _uploader_local_file + File.join(local_rails_root, fetch(:uploader_local_file, 'config/uploader.yml')) + end + + def _uploader_template + fetch(:uploader_template, 'uploader.yml.erb') + end + end