Module: ClusterBomb::Configuration
- Included in:
- Bomb::Config
- Defined in:
- lib/cluster_bomb/configuration.rb
Constant Summary
collapse
- HOME =
File.join(ENV["HOME"], ".cluster_bomb")
- CFG_FILE_NAME =
File.join(HOME,"config.yaml")
- KEYS =
{
:screen_width=>{:default=>120},
:logging=>{:default=>true},
:logfile=>{:default=>"logs/cb-#{Time.now().strftime('%m-%d-%Y')}.log}"},
:max_run_time=>{:default=>nil},
:max_history=>{:default=>1000},
:username=>{:default=>ENV["USER"]}
}
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/cluster_bomb/configuration.rb', line 73
def method_missing(symbol, *args)
str = symbol.to_s
if str.match(/=$/)
self.set(str.sub('=', ''),args[0])
else
self.get(str)
end
end
|
Class Method Details
.check_dir ⇒ Object
Check for home dir, and create it if it doesn’t exist
20
21
22
|
# File 'lib/cluster_bomb/configuration.rb', line 20
def self.check_dir
`mkdir #{HOME}` unless File.exists? HOME
end
|
Instance Method Details
#configuration ⇒ Object
28
29
30
|
# File 'lib/cluster_bomb/configuration.rb', line 28
def configuration
@configuration
end
|
#get(key) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/cluster_bomb/configuration.rb', line 37
def get(key)
k = key.class==Symbol ? key : key.to_sym
raise "Config.get ==> Uknown key #{k}" unless (@configuration.has_key? k or KEYS.has_key? k)
ret = @configuration[k] || KEYS[k][:default]
ret
end
|
#has_ssh_options?(username) ⇒ Boolean
69
70
71
72
|
# File 'lib/cluster_bomb/configuration.rb', line 69
def has_ssh_options?(username)
return true if @ssh_options_for_user[username]
File.exists? File.join(HOME,"ssh_#{username}.yml")
end
|
#initialize ⇒ Object
14
15
16
17
18
|
# File 'lib/cluster_bomb/configuration.rb', line 14
def initialize
@configuration={}
@ssh_options_for_user={} Configuration.check_dir
end
|
#keys ⇒ Object
43
44
45
|
# File 'lib/cluster_bomb/configuration.rb', line 43
def keys
KEYS.keys
end
|
#set(key, val) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/cluster_bomb/configuration.rb', line 31
def set(key, val)
k = key.class==Symbol ? key : key.to_sym
raise "Invalid setting [#{key}]" unless KEYS[k]
@configuration[k] = val
end
|
#ssh_options(username) ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/cluster_bomb/configuration.rb', line 61
def ssh_options(username)
if has_ssh_options? username
if !@ssh_options_for_user[username]
@ssh_options_for_user[username] = YAML.load(File.read(File.join(HOME,"ssh_#{username}.yml")))
end
end
@ssh_options_for_user[username] || {}
end
|
#valid_key?(k) ⇒ Boolean
46
47
48
|
# File 'lib/cluster_bomb/configuration.rb', line 46
def valid_key?(k)
KEYS.has_key? k.to_sym
end
|