Class: Capistrano::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/configuration.rb,
lib/capistrano/configuration/filter.rb,
lib/capistrano/configuration/server.rb,
lib/capistrano/configuration/servers.rb,
lib/capistrano/configuration/question.rb,
lib/capistrano/configuration/role_filter.rb,
lib/capistrano/configuration/null_filter.rb,
lib/capistrano/configuration/host_filter.rb,
lib/capistrano/configuration/empty_filter.rb,
lib/capistrano/configuration/regex_filter.rb

Defined Under Namespace

Modules: RegexFilter Classes: EmptyFilter, Filter, HostFilter, NullFilter, Question, RoleFilter, Server, Servers

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Configuration

Returns a new instance of Configuration



11
12
13
# File 'lib/capistrano/configuration.rb', line 11

def initialize(config = nil)
  @config ||= config
end

Instance Attribute Details

#backendObject



83
84
85
# File 'lib/capistrano/configuration.rb', line 83

def backend
  @backend ||= SSHKit
end

Class Method Details

.envObject



15
16
17
# File 'lib/capistrano/configuration.rb', line 15

def self.env
  @env ||= new
end

.reset!Object



19
20
21
# File 'lib/capistrano/configuration.rb', line 19

def self.reset!
  @env = new
end

Instance Method Details

#add_cmdline_filter(type, values) ⇒ Object



118
119
120
# File 'lib/capistrano/configuration.rb', line 118

def add_cmdline_filter(type, values)
  cmdline_filters << Filter.new(type, values)
end

#ask(key, default = nil, options = {}) ⇒ Object



23
24
25
26
# File 'lib/capistrano/configuration.rb', line 23

def ask(key, default=nil, options={})
  question = Question.new(key, default, options)
  set(key, question)
end

#configure_backendObject



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/capistrano/configuration.rb', line 89

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          = 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

#delete(key) ⇒ Object



37
38
39
# File 'lib/capistrano/configuration.rb', line 37

def delete(key)
  config.delete(key)
end

#fetch(key, default = nil, &block) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/capistrano/configuration.rb', line 41

def fetch(key, default=nil, &block)
  value = fetch_for(key, default, &block)
  while callable_without_parameters?(value)
    value = set(key, value.call)
  end
  return value
end

#filter(list) ⇒ Object



122
123
124
125
# File 'lib/capistrano/configuration.rb', line 122

def filter list
  setup_filters if @filters.nil?
  @filters.reduce(list) { |l,f| f.filter l }
end

#keysObject



55
56
57
# File 'lib/capistrano/configuration.rb', line 55

def keys
  config.keys
end

#primary(role) ⇒ Object



79
80
81
# File 'lib/capistrano/configuration.rb', line 79

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

#role(name, hosts, options = {}) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/capistrano/configuration.rb', line 59

def role(name, hosts, options={})
  if name == :all
    raise ArgumentError.new("#{name} reserved name for role. Please choose another name")
  end

  servers.add_role(name, hosts, options)
end

#role_properties_for(names, &block) ⇒ Object



75
76
77
# File 'lib/capistrano/configuration.rb', line 75

def role_properties_for(names, &block)
  servers.role_properties_for(names, &block)
end

#roles_for(names) ⇒ Object



71
72
73
# File 'lib/capistrano/configuration.rb', line 71

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

#server(name, properties = {}) ⇒ Object



67
68
69
# File 'lib/capistrano/configuration.rb', line 67

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

#set(key, value = nil, &block) ⇒ Object



28
29
30
31
# File 'lib/capistrano/configuration.rb', line 28

def set(key, value=nil, &block)
  invoke_validations(key, value, &block)
  config[key] = block || value
end

#set_if_empty(key, value = nil, &block) ⇒ Object



33
34
35
# File 'lib/capistrano/configuration.rb', line 33

def set_if_empty(key, value=nil, &block)
  set(key, value, &block) unless config.has_key? key
end

#setup_filtersObject



107
108
109
110
111
112
113
114
115
116
# File 'lib/capistrano/configuration.rb', line 107

def setup_filters
  @filters = cmdline_filters.clone
  @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

#timestampObject



103
104
105
# File 'lib/capistrano/configuration.rb', line 103

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

#validate(key, &validator) ⇒ Object



49
50
51
52
53
# File 'lib/capistrano/configuration.rb', line 49

def validate(key, &validator)
  vs = (validators[key] || [])
  vs << validator
  validators[key] = vs
end