Class: Marsdawn::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(file = './config/marsdawn.yml') ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
# File 'lib/marsdawn/config.rb', line 5

def initialize file='./config/marsdawn.yml'
  file = File.absolute_path(file)
  raise "Cannot find a config file for marsdawn." unless File.exists?(file)
  @config = YAML.load_file(file)
end

Instance Method Details

#eachObject



25
26
27
28
29
# File 'lib/marsdawn/config.rb', line 25

def each
  @config.keys.each do |key|
    yield key, to_hash(key)
  end
end

#get(key, entry, default = nil) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/marsdawn/config.rb', line 11

def get key, entry, default=nil
  conf = to_hash(key)
  conf[entry] = default if !default.nil? && !conf.key?(entry)
  raise "No entry '#{entry}' in the setting file of marsdawn." unless conf.key?(entry)
  ret = conf[entry]
  ret = Marsdawn::Util.hash_symbolize_keys(ret) if ret.kind_of?(Hash)
  ret
end

#to_hash(key) ⇒ Object



20
21
22
23
# File 'lib/marsdawn/config.rb', line 20

def to_hash key
  raise "Cannot find the configuration for '#{key}' in marsdawn.yml." unless @config.key?(key)
  Marsdawn::Util.hash_symbolize_keys(@config[key])
end