Class: RubyConfig::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#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

#default_handleObject



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

#loadObject



33
34
35
# File 'lib/ruby_config/config.rb', line 33

def load
  @hash = File.open(@config_file) { |yf| YAML::load( yf ) }
end

#saveObject



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_hashObject



37
38
39
# File 'lib/ruby_config/config.rb', line 37

def to_hash
  @hash
end