Class: Peony::Settings

Inherits:
Hash
  • Object
show all
Defined in:
lib/peony/settings.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/peony/settings.rb', line 3

def method_missing(method, *args, &block)
  name = method.to_s
  key, punct = name[0..-2].to_sym, name[-1..-1]
  case punct
  when '='
    self[key] = args.first != nil ? args.first : block
  when '?'
    include? key
  when '!'
    raise Error, "Setting :#{key} is not set" unless include?(key)
    evaluate self[key]
  else
    if include? method
      evaluate self[method]
    else
      block.call unless block.nil? 
    end
  end
end

Instance Method Details

#evaluate(value) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/peony/settings.rb', line 23

def evaluate(value)
  if value.is_a?(Proc)
    value.call
  else
    value
  end
end