Class: Typhon::Config

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/typhon/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.settingsObject (readonly)

Returns the value of attribute settings.



8
9
10
# File 'lib/typhon/config.rb', line 8

def settings
  @settings
end

Class Method Details

.[](key) ⇒ Object



14
15
16
# File 'lib/typhon/config.rb', line 14

def [](key)
    @settings[key]
end

.[]=(key, val) ⇒ Object



10
11
12
# File 'lib/typhon/config.rb', line 10

def []=(key,val)
    @settings[key] = val
end

.eachObject



22
23
24
25
26
# File 'lib/typhon/config.rb', line 22

def each
    @settings.each_pair do |k, v|
        yield({k => v})
    end
end

.include?(key) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/typhon/config.rb', line 18

def include?(key)
    @settings.include?(key)
end

.loadconfigObject



28
29
30
31
32
33
34
35
# File 'lib/typhon/config.rb', line 28

def loadconfig
    raise "Set configdir" unless @settings.include?(:configdir)

    file = File.join([@settings[:configdir], "typhon.yaml"])

    raise "Cannot find file #{file}" unless File.exist?(file)
    @settings.merge!(YAML.load_file(file))
end

.method_missing(k, *args, &block) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/typhon/config.rb', line 37

def method_missing(k, *args, &block)
    return @settings[k] if @settings.include?(k)

    k = k.to_s.gsub("_", ".")
    return @settings[k] if @settings.include?(k)

    super
end