Class: Capistrano::Configuration
- Inherits:
-
Object
- Object
- Capistrano::Configuration
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
Defined Under Namespace
Classes: Filter, Question, Server, Servers
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_cmdline_filter(type, values) ⇒ Object
-
#ask(key, default = nil, options = {}) ⇒ Object
-
#configure_backend ⇒ Object
-
#delete(key) ⇒ Object
-
#fetch(key, default = nil, &block) ⇒ Object
-
#filter(list) ⇒ Object
-
#initialize(config = nil) ⇒ Configuration
constructor
A new instance of Configuration.
-
#keys ⇒ Object
-
#primary(role) ⇒ Object
-
#role(name, hosts, options = {}) ⇒ Object
-
#role_properties_for(names, &block) ⇒ Object
-
#roles_for(names) ⇒ Object
-
#server(name, properties = {}) ⇒ Object
-
#set(key, value) ⇒ Object
-
#set_if_empty(key, value) ⇒ Object
-
#setup_filters ⇒ Object
-
#timestamp ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ Configuration
Returns a new instance of Configuration.
9
10
11
|
# File 'lib/capistrano/configuration.rb', line 9
def initialize(config = nil)
@config ||= config
end
|
Instance Attribute Details
#backend ⇒ Object
74
75
76
|
# File 'lib/capistrano/configuration.rb', line 74
def backend
@backend ||= SSHKit
end
|
Class Method Details
.env ⇒ Object
13
14
15
|
# File 'lib/capistrano/configuration.rb', line 13
def self.env
@env ||= new
end
|
.reset! ⇒ Object
17
18
19
|
# File 'lib/capistrano/configuration.rb', line 17
def self.reset!
@env = new
end
|
Instance Method Details
#add_cmdline_filter(type, values) ⇒ Object
107
108
109
|
# File 'lib/capistrano/configuration.rb', line 107
def add_cmdline_filter(type, values)
cmdline_filters << Filter.new(type, values)
end
|
#ask(key, default = nil, options = {}) ⇒ Object
21
22
23
24
|
# File 'lib/capistrano/configuration.rb', line 21
def ask(key, default=nil, options={})
question = Question.new(key, default, options)
set(key, question)
end
|
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/capistrano/configuration.rb', line 80
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
34
35
36
|
# File 'lib/capistrano/configuration.rb', line 34
def delete(key)
config.delete(key)
end
|
#fetch(key, default = nil, &block) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/capistrano/configuration.rb', line 38
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
111
112
113
114
|
# File 'lib/capistrano/configuration.rb', line 111
def filter list
setup_filters if @filters.nil?
@filters.reduce(list) { |l,f| f.filter l }
end
|
#keys ⇒ Object
46
47
48
|
# File 'lib/capistrano/configuration.rb', line 46
def keys
config.keys
end
|
#primary(role) ⇒ Object
70
71
72
|
# File 'lib/capistrano/configuration.rb', line 70
def primary(role)
servers.fetch_primary(role)
end
|
#role(name, hosts, options = {}) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/capistrano/configuration.rb', line 50
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
66
67
68
|
# File 'lib/capistrano/configuration.rb', line 66
def role_properties_for(names, &block)
servers.role_properties_for(names, &block)
end
|
#roles_for(names) ⇒ Object
62
63
64
|
# File 'lib/capistrano/configuration.rb', line 62
def roles_for(names)
servers.roles_for(names)
end
|
#server(name, properties = {}) ⇒ Object
58
59
60
|
# File 'lib/capistrano/configuration.rb', line 58
def server(name, properties={})
servers.add_host(name, properties)
end
|
#set(key, value) ⇒ Object
26
27
28
|
# File 'lib/capistrano/configuration.rb', line 26
def set(key, value)
config[key] = value
end
|
#set_if_empty(key, value) ⇒ Object
30
31
32
|
# File 'lib/capistrano/configuration.rb', line 30
def set_if_empty(key, value)
config[key] = value unless config.has_key? key
end
|
#setup_filters ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/capistrano/configuration.rb', line 98
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[:host]) if fh[:host]
@filters << Filter.new(:role, fh[:role]) if fh[:role]
end
|
#timestamp ⇒ Object
94
95
96
|
# File 'lib/capistrano/configuration.rb', line 94
def timestamp
@timestamp ||= Time.now.utc
end
|