Class: Zebra::Config
- Inherits:
-
Object
show all
- Includes:
- Singleton
- Defined in:
- lib/zebra/config.rb
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
15
16
17
|
# File 'lib/zebra/config.rb', line 15
def initialize
@config = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/zebra/config.rb', line 50
def method_missing(id, *args)
return nil unless @config.instance_of?(Hash)
method_name = id.id2name
if method_name =~ /^(.*?)\?$/
return @config.has_key?($1.to_sym) && !@config[$1.to_sym].nil?
elsif method_name =~ /^(.*?)\=$/
return @config[$1.to_sym] = args[0]
elsif @config.has_key?(method_name.to_sym)
return @config[method_name.to_sym]
else
return nil
end
end
|
Instance Method Details
#base_path ⇒ Object
38
39
40
|
# File 'lib/zebra/config.rb', line 38
def base_path
File.expand_path(File.dirname(__FILE__) + '/../../')
end
|
#config_file=(config_file) ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/zebra/config.rb', line 28
def config_file= config_file
@config[:config_file] = config_file
yaml = read_config_file(config_file)
config = YAML.load(yaml)
@config.deep_merge!(config)
@config.symbolize_keys!
return @config[:config_file]
end
|
#empty? ⇒ Boolean
46
47
48
|
# File 'lib/zebra/config.rb', line 46
def empty?
return @config.empty?
end
|
#nil? ⇒ Boolean
42
43
44
|
# File 'lib/zebra/config.rb', line 42
def nil?
return @config.empty?
end
|
#read_config_file(config_file) ⇒ Object
19
20
21
22
23
24
25
26
|
# File 'lib/zebra/config.rb', line 19
def read_config_file(config_file)
if File.exists?(config_file)
yaml = File.read(config_file)
else
raise ResourceNotFoundException.new("Unable to open #{config_file}")
end
return yaml
end
|