Class: Capistrano::Configuration::Servers
- Inherits:
-
Object
- Object
- Capistrano::Configuration::Servers
- Includes:
- Enumerable
- Defined in:
- lib/capistrano/configuration/servers.rb
Defined Under Namespace
Classes: ServerKey
Instance Method Summary collapse
- #add_host(host, properties = {}) ⇒ Object
-
#add_role(role, hosts, options = {}) ⇒ Object
rubocop:disable Security/MarshalLoad.
- #each ⇒ Object
- #fetch_primary(role) ⇒ Object
- #role_properties_for(rolenames) ⇒ Object
-
#roles_for(names) ⇒ Object
rubocop:enable Security/MarshalLoad.
Instance Method Details
#add_host(host, properties = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/capistrano/configuration/servers.rb', line 10 def add_host(host, properties={}) new_host = Server[host] new_host.port = properties[:port] if properties.key?(:port) # This matching logic must stay in sync with `Server#matches?`. key = ServerKey.new(new_host.hostname, new_host.port) existing = servers_by_key[key] if existing existing.user = new_host.user if new_host.user existing.with(properties) else servers_by_key[key] = new_host.with(properties) end end |
#add_role(role, hosts, options = {}) ⇒ Object
rubocop:disable Security/MarshalLoad
25 26 27 28 |
# File 'lib/capistrano/configuration/servers.rb', line 25 def add_role(role, hosts, ={}) = Marshal.dump(.merge(roles: role)) Array(hosts).each { |host| add_host(host, Marshal.load()) } end |
#each ⇒ Object
59 60 61 |
# File 'lib/capistrano/configuration/servers.rb', line 59 def each servers_by_key.values.each { |server| yield server } end |
#fetch_primary(role) ⇒ Object
54 55 56 57 |
# File 'lib/capistrano/configuration/servers.rb', line 54 def fetch_primary(role) hosts = roles_for([role]) hosts.find(&:primary) || hosts.first end |
#role_properties_for(rolenames) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/capistrano/configuration/servers.rb', line 37 def role_properties_for(rolenames) roles = rolenames.to_set rps = Set.new unless block_given? roles_for(rolenames).each do |host| host.roles.intersection(roles).each do |role| [host.properties.fetch(role)].flatten(1).each do |props| if block_given? yield host, role, props else rps << (props || {}).merge(role: role, hostname: host.hostname) end end end end block_given? ? nil : rps end |