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

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ Evaluator

Returns a new instance of Evaluator.

Parameters:

  • contents (String)


19
20
21
22
23
24
# File 'lib/buff/config/ruby.rb', line 19

def initialize(contents)
  @attributes = Hash.new
  instance_eval(contents)
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



31
32
33
34
35
36
37
# File 'lib/buff/config/ruby.rb', line 31

def method_missing(m, *args, &block)
  if args.size > 0
    attributes[m.to_sym] = (args.length == 1) ? args[0] : args
  else
    super
  end
end

Class Method Details

.parse(contents) ⇒ Hash

Parse the contents of the Ruby file into a Hash.

Parameters:

  • contents (String)

Returns:

  • (Hash)


13
14
15
# File 'lib/buff/config/ruby.rb', line 13

def parse(contents)
  self.new(contents).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}


27
28
29
# File 'lib/buff/config/ruby.rb', line 27

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