Class: Itamae::RecipeChildren

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

Constant Summary collapse

NotFoundError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#_dependency_in_dotObject



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/itamae/recipe_children.rb', line 73

def _dependency_in_dot
  result = ""

  recipes(recursive: false).each do |recipe|
    recipe.children.recipes(recursive: false).each do |child_recipe|
      result << %{  "#{recipe.path}" -> "#{child_recipe.path}";\n}
    end
    result << recipe.children._dependency_in_dot
  end

  result
end

#dependency_in_dotObject

returns dependencies graph in DOT



63
64
65
66
67
68
69
70
71
# File 'lib/itamae/recipe_children.rb', line 63

def dependency_in_dot
  result = ""
  result << "digraph recipes {\n"
  result << "  rankdir=LR;\n"
  result << _dependency_in_dot
  result << "}"

  result
end

#find_recipe_by_path(path) ⇒ Object



25
26
27
28
29
# File 'lib/itamae/recipe_children.rb', line 25

def find_recipe_by_path(path)
  recipes.find do |recipe|
    recipe.path == path
  end
end

#find_resource_by_description(desc) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/itamae/recipe_children.rb', line 5

def find_resource_by_description(desc)
  # desc is like 'resource_type[name]'
  resources.find do |resource|
    type, name = Itamae::Resource.parse_description(desc)
    resource.resource_type == type && resource.resource_name == name
  end.tap do |resource|
    unless resource
      raise NotFoundError, "'#{desc}' resource is not found."
    end
  end
end

#recipes(options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/itamae/recipe_children.rb', line 42

def recipes(options = {})
  options = {recursive: true}.merge(options)

  self.select do |item|
    item.is_a?(Recipe)
  end.map do |recipe|
    if options[:recursive]
      [recipe] + recipe.children.recipes
    else
      recipe
    end
  end.flatten
end

#resourcesObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/itamae/recipe_children.rb', line 31

def resources
  self.map do |item|
    case item
    when Resource::Base
      item
    when Recipe
      item.children.resources
    end
  end.flatten
end

#runObject



56
57
58
59
60
# File 'lib/itamae/recipe_children.rb', line 56

def run
  self.each do |resource|
    resource.run
  end
end

#subscribing(target) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/itamae/recipe_children.rb', line 17

def subscribing(target)
  resources.map do |resource|
    resource.subscriptions.select do |subscription|
      subscription.resource == target
    end
  end.flatten
end