Class: Gub::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/gub/config.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
9
10
11
|
# File 'lib/gub/config.rb', line 9
def initialize
read
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
32
33
34
|
# File 'lib/gub/config.rb', line 32
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
#data ⇒ Object
Returns the value of attribute data.
3
4
5
|
# File 'lib/gub/config.rb', line 3
def data
@data
end
|
Instance Method Details
#add(key, value) ⇒ Object
13
14
15
16
17
|
# File 'lib/gub/config.rb', line 13
def add key, value
self.data ||= {}
self.data[key] = value
self.write
end
|
#rc ⇒ Object
5
6
7
|
# File 'lib/gub/config.rb', line 5
def rc
File.expand_path("~/.gubrc")
end
|
#read ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/gub/config.rb', line 19
def read
if File.exists?(self.rc)
self.data = YAML.load_file(self.rc)
else
self.data = {}
end
end
|
#write ⇒ Object
27
28
29
30
|
# File 'lib/gub/config.rb', line 27
def write
puts data.inspect
File.open(self.rc, 'w') { |f| YAML.dump(self.data, f) }
end
|