Class: Codebase::Config

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, hash = {}) ⇒ Config

Returns a new instance of Config.



12
13
14
15
# File 'lib/codebase/config.rb', line 12

def initialize(filename, hash = {})
  @filename = filename
  @hash = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



17
18
19
# File 'lib/codebase/config.rb', line 17

def method_missing(name)
  @hash[name.to_s]
end

Class Method Details

.init(path = File.join(ENV['HOME'], '.codebase4')) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/codebase/config.rb', line 4

def self.init(path = File.join(ENV['HOME'], '.codebase4'))
  if File.exist?(path)
    self.new(path, YAML.load_file(path))
  else
    self.new(path)
  end
end

Instance Method Details

#saveObject



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

def save
  File.open(@filename, 'w') { |f| f.write(YAML.dump(@hash)) }
end

#set(name, value) ⇒ Object



21
22
23
24
25
# File 'lib/codebase/config.rb', line 21

def set(name, value)
  @hash[name.to_s] = value
  save
  value
end