Class: RubyConfig::Config
- Inherits:
-
Object
- Object
- RubyConfig::Config
- Defined in:
- lib/ruby_config/config.rb
Constant Summary collapse
- DEFAULTS =
{'default' => 'ruby-leopard-1.8.6'}
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(path) ⇒ Config
constructor
A new instance of Config.
- #load ⇒ Object
- #save ⇒ Object
- #set(key, value) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(path) ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 |
# File 'lib/ruby_config/config.rb', line 8 def initialize(path) @config_file = File.join(path, "config.yml") File.exist?(@config_file) ? load : @hash = {}.merge(DEFAULTS) #puts "config: #{@hash.inspect}" end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
4 5 6 |
# File 'lib/ruby_config/config.rb', line 4 def hash @hash end |
Instance Method Details
#get(key) ⇒ Object
15 16 17 |
# File 'lib/ruby_config/config.rb', line 15 def get(key) @hash[key] end |
#load ⇒ Object
27 28 29 |
# File 'lib/ruby_config/config.rb', line 27 def load @hash = RubyConfig::FileHelper.load_yml(@config_file) end |
#save ⇒ Object
23 24 25 |
# File 'lib/ruby_config/config.rb', line 23 def save RubyConfig::FileHelper.store_yml(@config_file, @hash) end |
#set(key, value) ⇒ Object
19 20 21 |
# File 'lib/ruby_config/config.rb', line 19 def set(key, value) @hash[key] = value end |
#to_hash ⇒ Object
31 32 33 |
# File 'lib/ruby_config/config.rb', line 31 def to_hash @hash end |