Class: Buff::Config::Ruby::Evaluator
- Inherits:
-
Object
- Object
- Buff::Config::Ruby::Evaluator
- Defined in:
- lib/buff/config/ruby.rb
Class Method Summary collapse
-
.parse(contents, path = nil, context = nil) ⇒ Hash
Parse the contents of the Ruby file into a Hash.
Instance Method Summary collapse
-
#initialize(contents, path = nil, context = nil) ⇒ Evaluator
constructor
A new instance of Evaluator.
- #method_missing(m, *args, &block) ⇒ Object
- #platform_specific_path(path) ⇒ Object
Constructor Details
#initialize(contents, path = nil, context = nil) ⇒ Evaluator
Returns a new instance of Evaluator.
24 25 26 27 28 29 30 31 |
# File 'lib/buff/config/ruby.rb', line 24 def initialize(contents, path=nil, context=nil) path ||= "(buff-config)" @context = context @attributes = Hash.new instance_eval(contents, path) rescue Exception => ex raise Errors::InvalidConfig, ex end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/buff/config/ruby.rb', line 38 def method_missing(m, *args, &block) if args.size > 0 attributes[m.to_sym] = (args.length == 1) ? args[0] : args elsif @context && @context.respond_to?(m) @context.send(m, *args, &block) else super end end |
Class Method Details
.parse(contents, path = nil, context = nil) ⇒ Hash
Parse the contents of the Ruby file into a Hash.
16 17 18 |
# File 'lib/buff/config/ruby.rb', line 16 def parse(contents, path=nil, context=nil) self.new(contents, path, context).send(:attributes) end |
Instance Method Details
#platform_specific_path(path) ⇒ Object
34 35 36 |
# File 'lib/buff/config/ruby.rb', line 34 def platform_specific_path(path) Buff::Config::Ruby.platform_specific_path(path) end |