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 ⇒ Object
Constructor Details
#initialize(runner, path) ⇒ Recipe
Returns a new instance of Recipe.
43 44 45 46 47 48 |
# File 'lib/itamae/recipe.rb', line 43 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.
7 8 9 |
# File 'lib/itamae/recipe.rb', line 7 def children @children end |
#delayed_notifications ⇒ Object (readonly)
Returns the value of attribute delayed_notifications.
8 9 10 |
# File 'lib/itamae/recipe.rb', line 8 def delayed_notifications @delayed_notifications end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/itamae/recipe.rb', line 5 def path @path end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
6 7 8 |
# File 'lib/itamae/recipe.rb', line 6 def runner @runner end |
Class Method Details
.find_recipe_in_gem(recipe) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/itamae/recipe.rb', line 11 def find_recipe_in_gem(recipe) plugin_name, recipe_file = recipe.split('::', 2) recipe_file = recipe_file.gsub("::", "/") if recipe_file gem_name = "itamae-plugin-recipe-#{plugin_name}" begin gem gem_name rescue LoadError end spec = Gem.loaded_specs.values.find do |spec| spec.name == gem_name end return nil unless spec candidate_files = [] if recipe_file recipe_file += '.rb' unless recipe_file.end_with?('.rb') candidate_files << "#{plugin_name}/#{recipe_file}" else candidate_files << "#{plugin_name}/default.rb" candidate_files << "#{plugin_name}.rb" end candidate_files.map do |file| File.join(spec.lib_dirs_glob, 'itamae', 'plugin', 'recipe', file) end.find do |path| File.exist?(path) end end |
Instance Method Details
#dir ⇒ Object
50 51 52 |
# File 'lib/itamae/recipe.rb', line 50 def dir ::File.dirname(@path) end |
#load(vars = {}) ⇒ Object
54 55 56 57 |
# File 'lib/itamae/recipe.rb', line 54 def load(vars = {}) context = EvalContext.new(self, vars) InstanceEval.new(File.read(path), path, 1, context: context).call end |