Sha256: 6baca643b0b557af8fa2f266dd1b265c6123edc8007b5a4c9fcecf698f4b4c47

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

Capistrano::Configuration.instance(:must_exist).load do
  namespace :shards do
    namespace :setup do
      desc "Upload configs"
      task :default, :roles => :app do
        if exists?(:shards_setup_settings)
          set(:recipe_settings) do
            {
              'main' => database_template_settings,
              'shards' => shards_template_settings
            }
          end
          put template.render(_shards_template), _shards_remote_path
        else
          puts "[FATAL] - Shards template settings were not found"
          abort
        end
      end

      desc "Download configs"
      task :get, :roles => :db do
        download _shards_remote_path, _shards_local_path
      end
    end

  end

  def shards_setup_defaults
    HashWithIndifferentAccess.new({
      'replicated'        => true,
      'verify_connection' => true,
      'environments'      => %w(production),
      'databases'         => {}
    })
  end

  def shards_template_settings
    DeepToHash.to_hash shards_setup_defaults.deep_merge(fetch(:shards_setup_settings, {}))
  end

  def _shards_remote_path
    File.join(shared_path, fetch(:shards_remote_path, 'config/shards.yml'))
  end

  def _shards_local_path
    File.join(local_rails_root, fetch(:shards_local_path, 'config/shards.yml'))
  end

  def _shards_template
    fetch(:shards_template, 'shards.yml.erb')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
marcosgz-cap-recipe-0.0.11 lib/capistrano/recipes/shards.rb
marcosgz-cap-recipe-0.0.10 lib/capistrano/recipes/shards.rb