Class: RubyConfig::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_config/config.rb

Constant Summary collapse

DEFAULTS =
{'default' => 'ruby-leopard-1.8.6'}

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hashObject

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

#loadObject



27
28
29
# File 'lib/ruby_config/config.rb', line 27

def load
  @hash = RubyConfig::FileHelper.load_yml(@config_file)
end

#saveObject



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_hashObject



31
32
33
# File 'lib/ruby_config/config.rb', line 31

def to_hash
  @hash
end