lib/itamae/recipe.rb in itamae-1.0.0.beta26 vs lib/itamae/recipe.rb in itamae-1.0.0.beta27

- old
+ new

@@ -1,63 +1,70 @@ require 'itamae' module Itamae class Recipe + NotFoundError = Class.new(StandardError) + attr_reader :path attr_reader :runner - attr_reader :dependencies - attr_reader :delayed_actions + attr_reader :children + attr_reader :delayed_notifications def initialize(runner, path) @runner = runner @path = path - @dependencies = RecipeDependencies.new - @delayed_actions = [] + @children = RecipeChildren.new + @delayed_notifications = [] - load_dependencies + load_children end def node @runner.node end def run(options = {}) - Logger.info "> Applying recipe... (#{@path})" + Logger.info "Recipe: #{@path}" - @dependencies.each do |resource| - case resource - when Resource::Base - resource.run(nil, dry_run: options[:dry_run]) - when Recipe - resource.run(options) - end - end + @children.run(options) - @delayed_actions.uniq.each do |action, resource| - resource.run(action, dry_run: options[:dry_run]) + @delayed_notifications.uniq do |notification| + [notification.action, notification.action_resource] + end.each do |notification| + notification.run(options) end Logger.info "< Finished. (#{@path})" end private - def load_dependencies + def load_children instance_eval(File.read(@path), @path, 1) end def method_missing(method, name, &block) klass = Resource.get_resource_class(method) resource = klass.new(self, name, &block) - @dependencies << resource + @children << resource rescue NameError super end def include_recipe(target) target = ::File.expand_path(target, File.dirname(@path)) + + unless File.exist?(target) + raise NotFoundError, "File not found. (#{target})" + end + + if runner.children.find_recipe_by_path(target) + Logger.debug "Recipe, #{target}, is skipped because it is already included" + return + end + recipe = Recipe.new(@runner, target) - @dependencies << recipe + @children << recipe end end end