Class: Itamae::RecipeChildren
- Inherits:
-
Array
- Object
- Array
- Itamae::RecipeChildren
- Defined in:
- lib/itamae/recipe_children.rb
Constant Summary collapse
- NotFoundError =
Class.new(StandardError)
Instance Method Summary collapse
- #find_recipe_by_path(path) ⇒ Object
- #find_resource_by_description(desc) ⇒ Object
- #recipes ⇒ Object
- #resources ⇒ Object
- #run(options) ⇒ Object
- #subscribing(target) ⇒ Object
Instance Method Details
#find_recipe_by_path(path) ⇒ Object
25 26 27 28 29 |
# File 'lib/itamae/recipe_children.rb', line 25 def find_recipe_by_path(path) recipes.find do |recipe| recipe.path == path end end |
#find_resource_by_description(desc) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/itamae/recipe_children.rb', line 5 def find_resource_by_description(desc) # desc is like 'resource_type[name]' resources.find do |resource| type, name = Itamae::Resource.parse_description(desc) resource.resource_type == type && resource.resource_name == name end.tap do |resource| unless resource raise NotFoundError, "'#{desc}' resource is not found." end end end |
#recipes ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/itamae/recipe_children.rb', line 42 def recipes self.select do |item| item.is_a?(Recipe) end.map do |recipe| [recipe] + recipe.children.recipes end.flatten end |
#resources ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/itamae/recipe_children.rb', line 31 def resources self.map do |item| case item when Resource::Base item when Recipe item.children.resources end end.flatten end |
#run(options) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/itamae/recipe_children.rb', line 50 def run() self.each do |resource| case resource when Resource::Base resource.run(nil, dry_run: [:dry_run]) when Recipe resource.run() end end end |
#subscribing(target) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/itamae/recipe_children.rb', line 17 def subscribing(target) resources.map do |resource| resource.subscriptions.select do |subscription| subscription.resource == target end end.flatten end |