Class: CobraCommander::Umbrella

Inherits:
Object
  • Object
show all
Defined in:
lib/cobra_commander/umbrella.rb

Overview

An umbrella application

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path) ⇒ Umbrella

Returns a new instance of Umbrella.



8
9
10
11
12
# File 'lib/cobra_commander/umbrella.rb', line 8

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/cobra_commander/umbrella.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/cobra_commander/umbrella.rb', line 6

def path
  @path
end

Instance Method Details

#add_source(key, source) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/cobra_commander/umbrella.rb', line 30

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

#componentsObject



38
39
40
# File 'lib/cobra_commander/umbrella.rb', line 38

def components
  @components.values
end

#dependencies_of(name) ⇒ Object



47
48
49
50
# File 'lib/cobra_commander/umbrella.rb', line 47

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

#dependents_of(component) ⇒ Object



42
43
44
45
# File 'lib/cobra_commander/umbrella.rb', line 42

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

#find(name) ⇒ Object



14
15
16
# File 'lib/cobra_commander/umbrella.rb', line 14

def find(name)
  @components[name]
end

#resolve(component_root_path) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/cobra_commander/umbrella.rb', line 22

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

#rootObject



18
19
20
# File 'lib/cobra_commander/umbrella.rb', line 18

def root
  @root_component
end