Class: Itamae::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/itamae/recipe.rb

Defined Under Namespace

Classes: EvalContext

Constant Summary collapse

NotFoundError =
Class.new(StandardError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner, path) ⇒ Recipe

Returns a new instance of Recipe


28
29
30
31
32
33
# File 'lib/itamae/recipe.rb', line 28

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

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children


9
10
11
# File 'lib/itamae/recipe.rb', line 9

def children
  @children
end

#delayed_notificationsObject (readonly)

Returns the value of attribute delayed_notifications


10
11
12
# File 'lib/itamae/recipe.rb', line 10

def delayed_notifications
  @delayed_notifications
end

#pathObject (readonly)

Returns the value of attribute path


7
8
9
# File 'lib/itamae/recipe.rb', line 7

def path
  @path
end

#runnerObject (readonly)

Returns the value of attribute runner


8
9
10
# File 'lib/itamae/recipe.rb', line 8

def runner
  @runner
end

Class Method Details

.find_recipe_in_gem(recipe) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/itamae/recipe.rb', line 13

def find_recipe_in_gem(recipe)
  target = recipe.gsub('::', '/')
  target += '.rb' if target !~ /\.rb$/
  plugin_name = recipe.split('::')[0]

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

  return nil unless spec

  File.join(spec.lib_dirs_glob, 'itamae', 'plugin', 'recipe', target)
end

Instance Method Details

#loadObject


35
36
37
# File 'lib/itamae/recipe.rb', line 35

def load
  EvalContext.new(self)
end

#run(options = {}) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/itamae/recipe.rb', line 39

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

  Logger.formatter.indent do
    @children.run(options)

    @delayed_notifications.uniq do |notification|
      [notification.action, notification.action_resource]
    end.each do |notification|
      notification.run(options)
    end
  end
end