Sha256: d997d915fdd70f579c8ca3396df9978757374c40d1e26ad1534d1ceaa8f88554

Contents?: true

Size: 1.66 KB

Versions: 5

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require_relative 'each_slice_state'

module AwsCftTools
  class TemplateSet
    ##
    # Simple derived information about templates.
    #
    module Dependencies
      ##
      # @param template [AwsCftTools::Template]
      # @param variable [#to_s]
      def provided(template, variable)
        @dependency_tree.provided(template.filename.to_s, variable.to_s)
      end

      ##
      # @param template [AwsCftTools::Template]
      # @param variable [#to_s]
      def required(template, variable)
        @dependency_tree.required(template.filename.to_s, variable.to_s)
      end

      ##
      # @param from [AwsCftTools::Template]
      # @param to [AwsCftTools::Template]
      #
      def linked(from, to)
        @dependency_tree.linked(from.filename.to_s, to.filename.to_s)
      end

      ##
      # Iterates through the sorted list and yields an array of templates with no unsatisfied dependencies,
      # up to the maximum slice size.
      #
      # @param maximum_slice_size [Integer]
      # @yield [Array<AwsCftTools::Template>] up to +maximum_slice_size+ templates with no unsatisfied
      #   dependencies
      #
      def each_slice(maximum_slice_size, &block)
        return unless block_given?
        # we want to start at the beginning and get up to <n> items for which all prior dependencies have
        # already been returned in a prior call
        state = EachSliceState.new(maximum_slice_size, &block)

        each do |template|
          state.add_template(template, @dependency_tree.dependencies_for(template.filename.to_s))
        end
        # catch the last templates
        state.process_slice
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aws-cft-tools-0.1.4 lib/aws_cft_tools/template_set/dependencies.rb
aws-cft-tools-0.1.3 lib/aws_cft_tools/template_set/dependencies.rb
aws-cft-tools-0.1.2 lib/aws_cft_tools/template_set/dependencies.rb
aws-cft-tools-0.1.1 lib/aws_cft_tools/template_set/dependencies.rb
aws-cft-tools-0.1.0 lib/aws_cft_tools/template_set/dependencies.rb