Class: Luban::Deployment::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/luban/deployment/configuration/core.rb,
lib/luban/deployment/configuration/filter.rb,
lib/luban/deployment/configuration/server.rb,
lib/luban/deployment/configuration/question.rb,
lib/luban/deployment/configuration/server_set.rb

Defined Under Namespace

Classes: Question, Server, ServerSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



7
8
9
10
# File 'lib/luban/deployment/configuration/core.rb', line 7

def initialize
  @variables = {}
  @servers = ServerSet.new
end

Instance Attribute Details

#serversObject (readonly)

Returns the value of attribute servers.



5
6
7
# File 'lib/luban/deployment/configuration/core.rb', line 5

def servers
  @servers
end

#variablesObject (readonly)

Returns the value of attribute variables.



4
5
6
# File 'lib/luban/deployment/configuration/core.rb', line 4

def variables
  @variables
end

Instance Method Details

#ask(key = nil, default:, prompt: nil, echo: true) ⇒ Object



58
59
60
61
62
# File 'lib/luban/deployment/configuration/core.rb', line 58

def ask(key=nil, default:, prompt: nil, echo: true)
  Question.new(default: default, prompt: prompt, echo: echo).call.tap do |answer|
    set(key, answer) unless key.nil?
  end
end

#delete(key) ⇒ Object



20
21
22
# File 'lib/luban/deployment/configuration/core.rb', line 20

def delete(key)
  @variables[key] = value
end

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



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/luban/deployment/configuration/core.rb', line 24

def fetch(key, default = nil, &blk)
  value = if block_given?
            @variables.fetch(key, &blk)
          else
            @variables.fetch(key, default)
          end
  while callable_without_parameters?(value) 
    value = set(key, value.call)
  end
  return value
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/luban/deployment/configuration/core.rb', line 40

def has_key?(key)
  @variables.has_key?(key)
end

#keysObject



36
37
38
# File 'lib/luban/deployment/configuration/core.rb', line 36

def keys
  @variables.keys
end

#primary(role) ⇒ Object



18
19
20
# File 'lib/luban/deployment/configuration/filter.rb', line 18

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

#release_roles(*names) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/luban/deployment/configuration/filter.rb', line 9

def release_roles(*names)
  if names.last.is_a?(Hash)
    names.last.merge(:exclude => :no_release)
  else
    names << { :exclude => :no_release }
  end
  roles(*names)
end

#role(name, hosts, **properties) ⇒ Object



44
45
46
47
48
49
# File 'lib/luban/deployment/configuration/core.rb', line 44

def role(name, hosts, **properties)
  if name == :all
    raise ArgumentError, 'Reserved role name, :all, is NOT allowed to use.'
  end
  @servers.add_hosts_for_role(name, hosts, properties)
end

#roles(*names) ⇒ Object



4
5
6
7
# File 'lib/luban/deployment/configuration/filter.rb', line 4

def roles(*names)
  opts = names.last.is_a?(::Hash) ? names.pop : {}
  filter_servers(servers.find_by_roles(filter_roles(names), opts))
end

#server(name, **properties) ⇒ Object



51
52
53
54
55
56
# File 'lib/luban/deployment/configuration/core.rb', line 51

def server(name, **properties)
  new_server = servers.add_host(name, properties)
  if new_server
    new_server.ssh_options = fetch(:ssh_options) || {}
  end
end

#set(key, value) ⇒ Object



12
13
14
# File 'lib/luban/deployment/configuration/core.rb', line 12

def set(key, value)
  @variables[key] = value  
end

#set_default(key, value) ⇒ Object



16
17
18
# File 'lib/luban/deployment/configuration/core.rb', line 16

def set_default(key, value)
  set(key, value) if @variables[key].nil?
end