Sha256: 0fce185873f1def0e12679eb57d4894c7bc4c504511b666c5128d6b8d6b1f534

Contents?: true

Size: 1.71 KB

Versions: 9

Compression:

Stored size: 1.71 KB

Contents

require_relative 'configuration/question'
require_relative 'configuration/servers'
require_relative 'configuration/server'

module Capistrano
  class Configuration

    class << self
      def env
        @env ||= new
      end
    end

    def ask(key, default=nil)
      question = Question.new(self, key, default)
      set(key, question)
    end

    def set(key, value)
      config[key] = value
    end

    def fetch(key, default=nil, &block)
      value = fetch_for(key, default, &block)
      if value.respond_to?(:call)
        set(key, value.call)
      else
        value
      end
    end

    def role(name, hosts, options={})
      servers.add_role(name, hosts, options)
    end

    def server(name, properties={})
      servers.add_host(name, properties)
    end

    def roles_for(names)
      servers.roles_for(names)
    end

    def primary(role)
      servers.fetch_primary(role)
    end

    def backend
      @backend ||= SSHKit
    end

    attr_writer :backend

    def configure_backend
      backend.configure do |sshkit|
        sshkit.format           = fetch(:format)
        sshkit.output_verbosity = fetch(:log_level)
        sshkit.default_env      = fetch(:default_env)
        sshkit.backend.configure do |backend|
          backend.pty                = fetch(:pty)
          backend.connection_timeout = fetch(:connection_timeout)
        end
      end
    end

    def timestamp
      @timestamp ||= Time.now.utc
    end

    private

    def servers
      @servers ||= Servers.new
    end

    def config
      @config ||= Hash.new
    end

    def fetch_for(key, default, &block)
      if block_given?
        config.fetch(key, &block)
      else
        config.fetch(key, default)
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
capistrano-3.0.0.pre13 lib/capistrano/configuration.rb
capistrano-3.0.0.pre12 lib/capistrano/configuration.rb
capistrano-3.0.0.pre11 lib/capistrano/configuration.rb
capistrano-3.0.0.pre10 lib/capistrano/configuration.rb
capistrano-3.0.0.pre7 lib/capistrano/configuration.rb
capistrano-3.0.0.pre6 lib/capistrano/configuration.rb
capistrano-3.0.0.pre5 lib/capistrano/configuration.rb
capistrano-3.0.0.pre4 lib/capistrano/configuration.rb
capistrano-3.0.0.pre3 lib/capistrano/configuration.rb