Sha256: eba1f211d028849335a80a6d33554fb8196f71b18f96ffe8319fc30238b84384

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module CobraCommander
  # Calculates directly & transitively affected components
  class Affected
    attr_reader :directly, :transitively

    def initialize(tree, changes, path)
      @changes = changes
      @path = path
      @transitively = Set.new
      @directly = Set.new
      find_dependencies(tree)
      @transitively.delete(name: UMBRELLA_APP_NAME, path: @path)
    end

    def needs_testing
      @needs_testing ||= (@directly + @transitively).map! do |component|
        File.join(component[:path], "test.sh")
      end
    end

  private

    def find_dependencies(parent_component)
      parent_component[:dependencies].each do |component|
        add_if_changed(component)
        find_dependencies(component)
      end
    end

    def add_if_changed(component)
      @changes.each do |change|
        if change.start_with?(component[:path])
          @directly << component.reject { |k| k == :dependencies || k == :ancestry }
          @transitively.merge component[:ancestry]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cobra_commander-0.1.2 lib/cobra_commander/affected.rb
cobra_commander-0.1.1 lib/cobra_commander/affected.rb