Class: ServerSettings::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/server_settings/role.rb

Direct Known Subclasses

RoleDB

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role, config) ⇒ Role

Returns a new instance of Role.



6
7
8
9
# File 'lib/server_settings/role.rb', line 6

def initialize(role, config)
  @name = role
  @config = load(config)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



30
31
32
33
34
# File 'lib/server_settings/role.rb', line 30

def method_missing(name, *args, &block)
  key = name.to_s
  return nil unless @config.has_key? key
  @config[key]
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/server_settings/role.rb', line 4

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/server_settings/role.rb', line 4

def name
  @name
end

Instance Method Details

#hostObject



26
27
28
# File 'lib/server_settings/role.rb', line 26

def host
  hosts.first
end

#hostsObject



22
23
24
# File 'lib/server_settings/role.rb', line 22

def hosts
  @config["hosts"] if @config.has_key?("hosts")
end

#load(config) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/server_settings/role.rb', line 11

def load(config)
  role_options = config.keys.select{|s| s != "hosts"}
  @settings = Hash[*role_options.map do |option_name|
                     [ "%#{option_name}", config[option_name].to_s]
                   end.flatten]
  if config.has_key?("hosts")
    config["hosts"]= HostCollection.new(config["hosts"], @settings)
  end
  config
end

#with_format(format) ⇒ Object



36
37
38
# File 'lib/server_settings/role.rb', line 36

def with_format(format)
  hosts.with_format(format)
end