Sha256: eb7351908ee1a32905456e0134a7e08b8c2ca63d38d5fc720744ac2c4b9ba774

Contents?: true

Size: 900 Bytes

Versions: 1

Compression:

Stored size: 900 Bytes

Contents

require 'itamae'

module Itamae
  class Recipe
    attr_reader :path
    attr_reader :runner

    def initialize(runner, path)
      @runner = runner
      @path = path
      @resources = []
      load_resources
    end

    def node
      @runner.node
    end

    def run
      @resources.each do |resource|
        Logger.info ">>> Executing #{resource.class.name} (#{resource.options})..."
        begin
          resource.run
        rescue Resources::CommandExecutionError
          Logger.error "<<< Failed."
          exit 2
        else
          Logger.info "<<< Succeeded."
        end
      end
    end

    private

    def load_resources
      instance_eval(File.read(@path), @path, 1)
    end

    def method_missing(method, name, &block)
      klass = Resources.get_resource_class(method)
      resource = klass.new(self, name, &block)
      @resources << resource
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
itamae-1.0.0.beta1 lib/itamae/recipe.rb