Class: Buff::Config::Ruby::Evaluator

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

Defined Under Namespace

Classes: Proxy

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents, path = nil, context = nil) ⇒ Evaluator

Returns a new instance of Evaluator.

Parameters:

  • contents (String)
  • path (String) (defaults to: nil)
  • context (Object) (defaults to: nil)


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 (private)



42
43
44
45
46
47
48
49
50
# File 'lib/buff/config/ruby.rb', line 42

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
    Proxy.new
  end
end

Class Method Details

.parse(contents, path = nil, context = nil) ⇒ Hash

Parse the contents of the Ruby file into a Hash.

Parameters:

  • contents (String)
  • path (String) (defaults to: nil)

    file that should be used as __FILE__ during eval

  • context (Object) (defaults to: nil)

    the parent Config object

Returns:

  • (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

See Also:

  • Buff::Config::Ruby::Evaluator.{Buff{Buff::Config{Buff::Config::Ruby{Buff::Config::Ruby.platform_specific_path}


34
35
36
# File 'lib/buff/config/ruby.rb', line 34

def platform_specific_path(path)
  Buff::Config::Ruby.platform_specific_path(path)
end