class Capistrano::Configuration

Attributes

backend[W]
variables[R]

Public Class Methods

env() click to toggle source
# File lib/capistrano/configuration.rb, line 13
def self.env
  @env ||= new
end
new(values={}) click to toggle source
# File lib/capistrano/configuration.rb, line 26
def initialize(values={})
  @variables = ValidatedVariables.new(Variables.new(values))
end
reset!() click to toggle source
# File lib/capistrano/configuration.rb, line 17
def self.reset!
  @env = new
end

Public Instance Methods

add_cmdline_filter(type, values) click to toggle source
# File lib/capistrano/configuration.rb, line 145
def add_cmdline_filter(type, values)
  cmdline_filters << Filter.new(type, values)
end
add_filter(filter=nil, &block) click to toggle source
# File lib/capistrano/configuration.rb, line 117
def add_filter(filter=nil, &block)
  if block
    raise ArgumentError, "Both a block and an object were given" if filter

    filter = Object.new
    def filter.filter(servers)
      block.call(servers)
    end
  elsif !filter.respond_to? :filter
    raise TypeError, "Provided custom filter <#{filter.inspect}> does " \
                     "not have a public 'filter' method"
  end
  @custom_filters ||= []
  @custom_filters << filter
end
any?(key) click to toggle source
# File lib/capistrano/configuration.rb, line 47
def any?(key)
  value = fetch(key)
  if value && value.respond_to?(:any?)
    begin
      return value.any?
    rescue ArgumentError # rubocop:disable Lint/HandleExceptions
      # Gracefully ignore values whose `any?` method doesn't accept 0 args
    end
  end

  !value.nil?
end
append(key, *values) click to toggle source
# File lib/capistrano/configuration.rb, line 39
def append(key, *values)
  set(key, Array(fetch(key)).concat(values))
end
ask(key, default=nil, options={}) click to toggle source
# File lib/capistrano/configuration.rb, line 30
def ask(key, default=nil, options={})
  question = Question.new(key, default, options)
  set(key, question)
end
backend() click to toggle source
# File lib/capistrano/configuration.rb, line 89
def backend
  @backend ||= SSHKit
end
configure_backend() click to toggle source
# File lib/capistrano/configuration.rb, line 95
def configure_backend
  backend.configure do |sshkit|
    configure_sshkit_output(sshkit)
    sshkit.output_verbosity = fetch(:log_level)
    sshkit.default_env      = fetch(:default_env)
    sshkit.backend          = fetch(:sshkit_backend, SSHKit::Backend::Netssh)
    sshkit.backend.configure do |backend|
      backend.pty                = fetch(:pty)
      backend.connection_timeout = fetch(:connection_timeout)
      backend.ssh_options        = (backend.ssh_options || {}).merge(fetch(:ssh_options, {}))
    end
  end
end
configure_scm() click to toggle source
# File lib/capistrano/configuration.rb, line 109
def configure_scm
  Capistrano::Configuration::SCMResolver.new.resolve
end
dry_run?() click to toggle source
# File lib/capistrano/configuration.rb, line 154
def dry_run?
  fetch(:sshkit_backend) == SSHKit::Backend::Printer
end
filter(list) click to toggle source
# File lib/capistrano/configuration.rb, line 149
def filter(list)
  setup_filters if @filters.nil?
  @filters.reduce(list) { |l, f| f.filter l }
end
install_plugin(plugin, load_hooks: true, load_immediately: false) click to toggle source
# File lib/capistrano/configuration.rb, line 158
def install_plugin(plugin, load_hooks: true, load_immediately: false)
  installer.install(plugin,
                    load_hooks: load_hooks,
                    load_immediately: load_immediately)
end
is_question?(key) click to toggle source
# File lib/capistrano/configuration.rb, line 60
def is_question?(key)
  value = fetch_for(key, nil)
  !value.nil? && value.is_a?(Question)
end
primary(role) click to toggle source
# File lib/capistrano/configuration.rb, line 85
def primary(role)
  servers.fetch_primary(role)
end
remove(key, *values) click to toggle source
# File lib/capistrano/configuration.rb, line 43
def remove(key, *values)
  set(key, Array(fetch(key)) - values)
end
role(name, hosts, options={}) click to toggle source
# File lib/capistrano/configuration.rb, line 65
def role(name, hosts, options={})
  if name == :all
    raise ArgumentError, "#{name} reserved name for role. Please choose another name"
  end

  servers.add_role(name, hosts, options)
end
role_properties_for(names, &block) click to toggle source
# File lib/capistrano/configuration.rb, line 81
def role_properties_for(names, &block)
  servers.role_properties_for(names, &block)
end
roles_for(names) click to toggle source
# File lib/capistrano/configuration.rb, line 77
def roles_for(names)
  servers.roles_for(names)
end
scm_plugin_installed?() click to toggle source
# File lib/capistrano/configuration.rb, line 164
def scm_plugin_installed?
  installer.scm_installed?
end
server(name, properties={}) click to toggle source
# File lib/capistrano/configuration.rb, line 73
def server(name, properties={})
  servers.add_host(name, properties)
end
servers() click to toggle source
# File lib/capistrano/configuration.rb, line 168
def servers
  @servers ||= Servers.new
end
set_if_empty(key, value=nil, &block) click to toggle source
# File lib/capistrano/configuration.rb, line 35
def set_if_empty(key, value=nil, &block)
  set(key, value, &block) unless keys.include?(key)
end
setup_filters() click to toggle source
# File lib/capistrano/configuration.rb, line 133
def setup_filters
  @filters = cmdline_filters
  @filters += @custom_filters if @custom_filters
  @filters << Filter.new(:role, ENV["ROLES"]) if ENV["ROLES"]
  @filters << Filter.new(:host, ENV["HOSTS"]) if ENV["HOSTS"]
  fh = fetch_for(:filter, {}) || {}
  @filters << Filter.new(:host, fh[:hosts]) if fh[:hosts]
  @filters << Filter.new(:role, fh[:roles]) if fh[:roles]
  @filters << Filter.new(:host, fh[:host]) if fh[:host]
  @filters << Filter.new(:role, fh[:role]) if fh[:role]
end
timestamp() click to toggle source
# File lib/capistrano/configuration.rb, line 113
def timestamp
  @timestamp ||= Time.now.utc
end

Private Instance Methods

cmdline_filters() click to toggle source
# File lib/capistrano/configuration.rb, line 174
def cmdline_filters
  @cmdline_filters ||= []
end
configure_sshkit_output(sshkit) click to toggle source
# File lib/capistrano/configuration.rb, line 182
def configure_sshkit_output(sshkit)
  format_args = [fetch(:format)]
  format_args.push(fetch(:format_options)) if any?(:format_options)

  sshkit.use_format(*format_args)
end
installer() click to toggle source
# File lib/capistrano/configuration.rb, line 178
def installer
  @installer ||= PluginInstaller.new
end