Class: Mozzn::Config
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
11
12
13
|
# File 'lib/mozzn/config.rb', line 11
def initialize
read
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
33
34
35
|
# File 'lib/mozzn/config.rb', line 33
def method_missing meth, *args, &block
self.data[meth.to_s] if self.data && self.data.has_key?(meth.to_s)
end
|
Instance Attribute Details
Returns the value of attribute data.
5
6
7
|
# File 'lib/mozzn/config.rb', line 5
def data
@data
end
|
Instance Method Details
#add(key, value) ⇒ Object
15
16
17
18
19
|
# File 'lib/mozzn/config.rb', line 15
def add key, value
self.data ||= {}
self.data[key] = value
self.write
end
|
7
8
9
|
# File 'lib/mozzn/config.rb', line 7
def rc
File.expand_path("~/.mozznrc")
end
|
21
22
23
24
25
26
27
|
# File 'lib/mozzn/config.rb', line 21
def read
if File.exists?(self.rc)
self.data = YAML.load_file(self.rc)
else
self.data = {}
end
end
|
29
30
31
|
# File 'lib/mozzn/config.rb', line 29
def write
File.open(self.rc, 'w') { |f| YAML.dump(self.data, f) }
end
|