Class: Itamae::Recipe
- Inherits:
-
Object
- Object
- Itamae::Recipe
- Defined in:
- lib/itamae/recipe.rb
Direct Known Subclasses
Defined Under Namespace
Classes: EvalContext, RecipeFromDefinition
Constant Summary collapse
- NotFoundError =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#delayed_notifications ⇒ Object
readonly
Returns the value of attribute delayed_notifications.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Class Method Summary collapse
Instance Method Summary collapse
- #dir ⇒ Object
-
#initialize(runner, path) ⇒ Recipe
constructor
A new instance of Recipe.
- #load(vars = {}) ⇒ Object
- #run(options = {}) ⇒ Object
Constructor Details
#initialize(runner, path) ⇒ Recipe
Returns a new instance of Recipe.
28 29 30 31 32 33 |
# File 'lib/itamae/recipe.rb', line 28 def initialize(runner, path) @runner = runner @path = path @delayed_notifications = [] @children = RecipeChildren.new end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
9 10 11 |
# File 'lib/itamae/recipe.rb', line 9 def children @children end |
#delayed_notifications ⇒ Object (readonly)
Returns the value of attribute delayed_notifications.
10 11 12 |
# File 'lib/itamae/recipe.rb', line 10 def delayed_notifications @delayed_notifications end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/itamae/recipe.rb', line 7 def path @path end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
8 9 10 |
# File 'lib/itamae/recipe.rb', line 8 def runner @runner end |
Class Method Details
.find_recipe_in_gem(recipe) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/itamae/recipe.rb', line 13 def find_recipe_in_gem(recipe) target = recipe.gsub('::', '/') target += '.rb' if target !~ /\.rb$/ plugin_name = recipe.split('::')[0] spec = Gem.loaded_specs.values.find do |spec| spec.name == "itamae-plugin-recipe-#{plugin_name}" end return nil unless spec File.join(spec.lib_dirs_glob, 'itamae', 'plugin', 'recipe', target) end |
Instance Method Details
#dir ⇒ Object
35 36 37 |
# File 'lib/itamae/recipe.rb', line 35 def dir ::File.dirname(@path) end |
#load(vars = {}) ⇒ Object
39 40 41 42 |
# File 'lib/itamae/recipe.rb', line 39 def load(vars = {}) context = EvalContext.new(self, vars) context.instance_eval(File.read(path), path, 1) end |
#run(options = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/itamae/recipe.rb', line 44 def run( = {}) Logger.formatter.with_indent do @children.run() @delayed_notifications.uniq do |notification| [notification.action, notification.action_resource] end.each do |notification| notification.run() end end end |