Class: Itamae::Recipe::EvalContext
- Inherits:
-
Object
- Object
- Itamae::Recipe::EvalContext
show all
- Defined in:
- lib/itamae/recipe.rb
Instance Method Summary
collapse
Constructor Details
#initialize(recipe, vars) ⇒ EvalContext
Returns a new instance of EvalContext.
65
66
67
68
69
70
71
|
# File 'lib/itamae/recipe.rb', line 65
def initialize(recipe, vars)
@recipe = recipe
vars.each do |k, v|
define_singleton_method(k) { v }
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/itamae/recipe.rb', line 80
def method_missing(*args, &block)
super unless args.size == 2
method, name = args
begin
klass = Resource.get_resource_class(method)
rescue NameError
super
end
resource = klass.new(@recipe, name, &block)
@recipe.children << resource
end
|
Instance Method Details
#define(name, params = {}, &block) ⇒ Object
#include_recipe(target) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/itamae/recipe.rb', line 98
def include_recipe(target)
candidate_paths = [
::File.expand_path(target, File.dirname(@recipe.path)),
Recipe.find_recipe_in_gem(target),
].compact
path = candidate_paths.find {|path| File.exist?(path) }
unless path
raise NotFoundError, "Recipe not found. (#{target})"
end
if runner.children.find_recipe_by_path(path)
Logger.debug "Recipe, #{path}, is skipped because it is already included"
return
end
recipe = Recipe.new(runner, path)
@recipe.children << recipe
recipe.load
end
|
#node ⇒ Object
119
120
121
|
# File 'lib/itamae/recipe.rb', line 119
def node
runner.node
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
73
74
75
76
77
78
|
# File 'lib/itamae/recipe.rb', line 73
def respond_to_missing?(method, include_private = false)
Resource.get_resource_class(method)
true
rescue NameError
false
end
|
#runner ⇒ Object
123
124
125
|
# File 'lib/itamae/recipe.rb', line 123
def runner
@recipe.runner
end
|