Sha256: 9fa6ef6d4af6551dc2090631d29859319eaaffa96df7d5355abaf9f0e4080984

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

require 'itamae'

module Itamae
  class Recipe
    attr_reader :path
    attr_reader :runner
    attr_reader :dependencies
    attr_reader :delayed_actions

    def initialize(runner, path)
      @runner = runner
      @path = path
      @dependencies = RecipeDependencies.new
      @delayed_actions = []

      load_dependencies
    end

    def node
      @runner.node
    end

    def run(options = {})
      Logger.info "> Applying 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

      @delayed_actions.uniq.each do |action, resource|
        resource.run(action, dry_run: options[:dry_run])
      end

      Logger.info "< Finished. (#{@path})"
    end

    private

    def load_dependencies
      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
    rescue NameError
      super
    end

    def include_recipe(target)
      target = ::File.expand_path(target, File.dirname(@path))
      recipe = Recipe.new(@runner, target)
      @dependencies << recipe
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itamae-1.0.0.beta26 lib/itamae/recipe.rb
itamae-1.0.0.beta25 lib/itamae/recipe.rb
itamae-1.0.0.beta24 lib/itamae/recipe.rb