Sha256: 8d7ff9a557f3bb9abd33fb0491e3601e2e154d5e0be75fb9b273569cbb035e71

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

require 'itamae'

module Itamae
  class Recipe
    NotFoundError = Class.new(StandardError)

    attr_reader :path
    attr_reader :runner
    attr_reader :children
    attr_reader :delayed_notifications

    def initialize(runner, path)
      @runner = runner
      @path = path
      @children = RecipeChildren.new
      @delayed_notifications = []

      load_children
    end

    def node
      @runner.node
    end

    def run(options = {})
      Logger.info "Recipe: #{@path}"

      @children.run(options)

      @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_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)
      @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)
      @children << recipe
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itamae-1.0.0.beta29 lib/itamae/recipe.rb
itamae-1.0.0.beta28 lib/itamae/recipe.rb
itamae-1.0.0.beta27 lib/itamae/recipe.rb