Sha256: 4563d27ef31812826a44b6129f4b48856c006509c64275383876eaccaa867dc4

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module CobraCommander
  # An umbrella application
  class Umbrella
    attr_reader :name, :path

    def initialize(name, path)
      @root_component = Component.new(self, name)
      @path = path
      @components = {}
    end

    def find(name)
      @components[name]
    end

    def root
      @root_component
    end

    def resolve(component_root_path)
      return root if root.root_paths.include?(component_root_path)

      components.find do |component|
        component.root_paths.include?(component_root_path)
      end
    end

    def add_source(key, source)
      @root_component.add_source key, source.path, source.dependencies
      source.components.each do |path:, name:, dependencies:|
        @components[name] ||= Component.new(self, name)
        @components[name].add_source key, path, dependencies
      end
    end

    def components
      @components.values
    end

    def dependents_of(component)
      find(component)&.deep_dependents
                     &.sort_by(&:name)
    end

    def dependencies_of(name)
      find(name)&.deep_dependencies
                &.sort_by(&:name)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cobra_commander-0.10.0 lib/cobra_commander/umbrella.rb
cobra_commander-0.9.2 lib/cobra_commander/umbrella.rb
cobra_commander-0.9.1 lib/cobra_commander/umbrella.rb