Class: RubyConfig::Config
- Inherits:
-
Object
- Object
- RubyConfig::Config
- Defined in:
- lib/ruby_config/config.rb
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
Instance Method Summary collapse
- #default_handle ⇒ Object
- #default_handle=(handle) ⇒ Object
- #get(key) ⇒ Object
-
#initialize(path) ⇒ Config
constructor
DEFAULTS = { ‘default’ => ‘ruby-leopard-1.8.6’ }.
- #load ⇒ Object
- #save ⇒ Object
- #set(key, value) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(path) ⇒ Config
DEFAULTS = { ‘default’ => ‘ruby-leopard-1.8.6’ }
8 9 10 11 |
# 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) 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
#default_handle ⇒ Object
13 14 15 |
# File 'lib/ruby_config/config.rb', line 13 def default_handle get('default') end |
#default_handle=(handle) ⇒ Object
17 18 19 |
# File 'lib/ruby_config/config.rb', line 17 def default_handle=(handle) set('default', handle) end |
#get(key) ⇒ Object
21 22 23 |
# File 'lib/ruby_config/config.rb', line 21 def get(key) @hash[key] end |
#load ⇒ Object
33 34 35 |
# File 'lib/ruby_config/config.rb', line 33 def load @hash = File.open(@config_file) { |yf| YAML::load( yf ) } end |
#save ⇒ Object
29 30 31 |
# File 'lib/ruby_config/config.rb', line 29 def save File.open(@config_file, 'w') { |out| YAML.dump( @hash, out ) } end |
#set(key, value) ⇒ Object
25 26 27 |
# File 'lib/ruby_config/config.rb', line 25 def set(key, value) @hash[key] = value end |
#to_hash ⇒ Object
37 38 39 |
# File 'lib/ruby_config/config.rb', line 37 def to_hash @hash end |