Class: Ferry::Configuration::Server

Inherits:
SSHKit::Host
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ferry/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/ferry/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/ferry/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/ferry/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/ferry/configuration/server.rb', line 23

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

#matches?(other) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/ferry/configuration/server.rb', line 64

def matches?(other)
  hostname == other.hostname
end

#netssh_optionsObject



56
57
58
# File 'lib/ferry/configuration/server.rb', line 56

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

#primaryObject



43
44
45
# File 'lib/ferry/configuration/server.rb', line 43

def primary
  self if fetch(:primary)
end

#propertiesObject



52
53
54
# File 'lib/ferry/configuration/server.rb', line 52

def properties
  @properties ||= Properties.new
end

#roles_arrayObject



60
61
62
# File 'lib/ferry/configuration/server.rb', line 60

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
# File 'lib/ferry/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
      self.fetch(k) == v
    end
    return false unless result
  end
  return true
end

#with(properties) ⇒ Object



47
48
49
50
# File 'lib/ferry/configuration/server.rb', line 47

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