Class: Build::Environment::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/build/environment/evaluator.rb

Instance Method Summary collapse

Constructor Details

#initialize(environment) ⇒ Evaluator

Returns a new instance of Evaluator.


24
25
26
27
# File 'lib/build/environment/evaluator.rb', line 24

def initialize(environment)
	@environment = environment
	@cache = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object


40
41
42
# File 'lib/build/environment/evaluator.rb', line 40

def method_missing(name)
	@cache[name] ||= object_value(@environment[name])
end

Instance Method Details

#initialize_dup(other) ⇒ Object


29
30
31
32
33
34
# File 'lib/build/environment/evaluator.rb', line 29

def initialize_dup(other)
	@environment = other.instance_variable_get(:@environment)
	@cache = other.instance_variable_get(:@cache).dup
	
	super
end

#object_value(value) ⇒ Object

Compute the literal object value for a given key:


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/build/environment/evaluator.rb', line 45

def object_value(value)
	case value
	when Array
		value.collect{|item| object_value(item)}.flatten
	when Symbol
		object_value(@environment[value])
	when Proc
		object_value(instance_exec(&value))
	when Default
		object_value(value.value)
	when Replace
		object_value(value.value)
	else
		value
	end
end

#respond_to?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

36
37
38
# File 'lib/build/environment/evaluator.rb', line 36

def respond_to?(name, include_private = false)
	@environment.include?(name) || super
end