Class: Capistrano::Configuration::Server

Inherits:
SSHKit::Host
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/capistrano/configuration/server.rb

Defined Under Namespace

Classes: Properties

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](host) ⇒ Object



8
9
10
# File 'lib/capistrano/configuration/server.rb', line 8

def self.[](host)
  host.is_a?(Server) ? host : new(host)
end

Instance Method Details

#add_role(role) ⇒ Object



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

def add_role(role)
  roles.add role.to_sym
  self
end

#add_roles(roles) ⇒ Object Also known as: roles=



12
13
14
15
# File 'lib/capistrano/configuration/server.rb', line 12

def add_roles(roles)
  Array(roles).each { |role| add_role(role) }
  self
end

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_role?(role)
  roles.include? role.to_sym
end

#matches?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(other)
  # This matching logic must stay in sync with `Servers#add_host`.
  hostname == other.hostname && port == other.port
end

#netssh_optionsObject



58
59
60
# File 'lib/capistrano/configuration/server.rb', line 58

def netssh_options
  @netssh_options ||= super.merge(fetch(:ssh_options) || {})
end

#primaryObject



45
46
47
# File 'lib/capistrano/configuration/server.rb', line 45

def primary
  self if fetch(:primary)
end

#propertiesObject



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

def properties
  @properties ||= Properties.new
end

#roles_arrayObject



62
63
64
# File 'lib/capistrano/configuration/server.rb', line 62

def roles_array
  roles.to_a
end

#select?(options) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/capistrano/configuration/server.rb', line 27

def select?(options)
  options.each do |k, v|
    callable = v.respond_to?(:call) ? v : ->(server) { server.fetch(v) }
    result = \
      case k
      when :filter, :select
        callable.call(self)
      when :exclude
        !callable.call(self)
      else
        fetch(k) == v
      end
    return false unless result
  end

  true
end

#with(properties) ⇒ Object



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

def with(properties)
  properties.each { |key, value| add_property(key, value) }
  self
end