Class: ServerSettings::RoleDB
- Inherits:
-
Role
- Object
- Role
- ServerSettings::RoleDB
show all
- Includes:
- Enumerable
- Defined in:
- lib/server_settings/role_db.rb
Instance Attribute Summary
Attributes inherited from Role
#config, #name
Instance Method Summary
collapse
Methods inherited from Role
#host, #initialize, #load, #method_missing, #with_format
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ServerSettings::Role
Instance Method Details
#build_db(name, config, group = nil) ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/server_settings/role_db.rb', line 10
def build_db(name, config, group = nil)
db = Database.new(name, group)
db.master = config[:master]
db.backup = config[:backup]
db.slaves = config[:slaves]
db.settings = config_params(config)
return db
end
|
#config_params(config) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/server_settings/role_db.rb', line 50
def config_params(config)
exclude_settings = [ :master, :backup, :slaves ]
config_keys = config.keys.select do |s|
s.is_a?(Symbol) and not exclude_settings.include?(s)
end
Hash[*config_keys.map {|s| [s, config[s]] }.flatten]
end
|
#databases ⇒ Object
6
7
8
|
# File 'lib/server_settings/role_db.rb', line 6
def databases
@config.keys.select { |a| a.kind_of?(String) }
end
|
#each {|default_db| ... } ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/server_settings/role_db.rb', line 23
def each
default_db = build_db("default", @config)
yield default_db
databases.each do |db_name|
config = @config[db_name]
if config && config.has_key?(:master)
db = build_db(db_name, config)
db.settings = default_db.settings.merge(db.settings)
yield db
else
group_name = db_name
config.map do |nest_db_name, nest_config|
db = build_db(nest_db_name, nest_config, group_name)
db.settings = default_db.settings.merge(db.settings)
yield db
end
end
end
end
|
#find(db_name) ⇒ Object
19
20
21
|
# File 'lib/server_settings/role_db.rb', line 19
def find(db_name)
select { |s| s.name == db_name }.first
end
|
#hosts ⇒ Object
46
47
48
|
# File 'lib/server_settings/role_db.rb', line 46
def hosts
find_all
end
|