Class: Falcore::Config

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

Defined Under Namespace

Classes: Parser

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/falcore/config.rb', line 90

def method_missing(m, *args, &block)
  key = m.to_s

  if key.include?('=')
    set(key.delete('='), args.first)
  else
    if has_key?(key)
      get(key)
    else
      NullObject.new
    end
  end
end

Class Method Details

.from_file(path) ⇒ Object



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

def from_file(path)
  contents = File.read(File.expand_path(path))
  parse(contents)
rescue Errno::ENOENT
  raise "No config found at '#{path}'!"
end

.parse(contents) ⇒ Object



29
30
31
# File 'lib/falcore/config.rb', line 29

def parse(contents)
  Parser.new(contents).parse
end

Instance Method Details

#respond_to_missing?(m, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
108
109
110
111
112
113
# File 'lib/falcore/config.rb', line 105

def respond_to_missing?(m, include_private = false)
  key = m.to_s

  if key.include?('=')
    true
  else
    has_key?(key) || super
  end
end