class Itamae::Recipe

Constants

NotFoundError

Attributes

children[R]
delayed_notifications[R]
path[R]
runner[R]

Public Class Methods

find_recipe_in_gem(recipe) click to toggle source
# File lib/itamae/recipe.rb, line 11
def find_recipe_in_gem(recipe)
  plugin_name, recipe_file = recipe.split('::', 2)
  recipe_file = recipe_file.gsub("::", "/") if recipe_file

  gem_name = "itamae-plugin-recipe-#{plugin_name}"
  begin
    gem gem_name
  rescue LoadError
  end
  spec = Gem.loaded_specs.values.find do |spec|
    spec.name == gem_name
  end

  return nil unless spec

  candidate_files = []
  if recipe_file
    recipe_file += '.rb' unless recipe_file.end_with?('.rb')
    candidate_files << "#{plugin_name}/#{recipe_file}"
  else
    candidate_files << "#{plugin_name}/default.rb"
    candidate_files << "#{plugin_name}.rb"
  end

  candidate_files.map do |file|
    File.join(spec.lib_dirs_glob, 'itamae', 'plugin', 'recipe', file)
  end.find do |path|
    File.exist?(path)
  end
end
new(runner, path) click to toggle source
# File lib/itamae/recipe.rb, line 43
def initialize(runner, path)
  @runner = runner
  @path = path
  @delayed_notifications = []
  @children = RecipeChildren.new
end

Public Instance Methods

dir() click to toggle source
# File lib/itamae/recipe.rb, line 50
def dir
  ::File.dirname(@path)
end
load(vars = {}) click to toggle source
# File lib/itamae/recipe.rb, line 54
def load(vars = {})
  context = EvalContext.new(self, vars)
  InstanceEval.new(File.read(path), path, 1, context: context).call
end
run() click to toggle source
# File lib/itamae/recipe.rb, line 59
def run
  show_banner

  @runner.handler.event(:recipe, path: @path) do
    Itamae.logger.with_indent do
      @children.run
      run_delayed_notifications
    end
  end
end

Private Instance Methods

run_delayed_notifications() click to toggle source
# File lib/itamae/recipe.rb, line 72
def run_delayed_notifications
  @delayed_notifications.uniq! do |notification|
    [notification.action, notification.action_resource]
  end

  while notification = @delayed_notifications.shift
    notification.run
  end
end
show_banner() click to toggle source
# File lib/itamae/recipe.rb, line 82
def show_banner
  Itamae.logger.info "Recipe: #{@path}"
end