Sha256: 4c51482cbbc6ed6b341ab34d4b5683a861d2ad5211bba1280ca5945dc9783a61

Contents?: true

Size: 1.39 KB

Versions: 47

Compression:

Stored size: 1.39 KB

Contents

module Itamae
  class RecipeChildren < Array
    NotFoundError = Class.new(StandardError)

    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

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

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

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

    def recipes
      self.select do |item|
        item.is_a?(Recipe)
      end.map do |recipe|
        [recipe] + recipe.children.recipes
      end.flatten
    end

    def run(options)
      self.each do |resource|
        case resource
        when Resource::Base
          resource.run(nil, dry_run: options[:dry_run])
        when Recipe
          resource.run(options)
        end
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
itamae-1.1.9 lib/itamae/recipe_children.rb
itamae-1.1.8 lib/itamae/recipe_children.rb
itamae-1.1.7 lib/itamae/recipe_children.rb
itamae-1.1.5 lib/itamae/recipe_children.rb
itamae-1.1.4 lib/itamae/recipe_children.rb
itamae-1.1.3 lib/itamae/recipe_children.rb
itamae-1.1.2 lib/itamae/recipe_children.rb
itamae-1.1.1 lib/itamae/recipe_children.rb
itamae-1.1.0 lib/itamae/recipe_children.rb
itamae-1.0.13 lib/itamae/recipe_children.rb
itamae-1.0.12 lib/itamae/recipe_children.rb
itamae-1.0.11 lib/itamae/recipe_children.rb
itamae-1.0.10 lib/itamae/recipe_children.rb
itamae-1.0.9 lib/itamae/recipe_children.rb
itamae-1.0.8 lib/itamae/recipe_children.rb
itamae-1.0.7 lib/itamae/recipe_children.rb
itamae-1.0.6 lib/itamae/recipe_children.rb
itamae-1.0.5 lib/itamae/recipe_children.rb
itamae-1.0.4 lib/itamae/recipe_children.rb
itamae-1.0.3 lib/itamae/recipe_children.rb