Class: CobraCommander::Component

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

Overview

Represents a component withing an Umbrella

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(umbrella, name) ⇒ Component

Returns a new instance of Component.



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

def initialize(umbrella, name)
  @umbrella = umbrella
  @name = name
  @dependency_names = []
  @packages = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#packagesObject (readonly)

Returns the value of attribute packages.



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

def packages
  @packages
end

Instance Method Details

#add_package(package) ⇒ Object



19
20
21
22
# File 'lib/cobra_commander/component.rb', line 19

def add_package(package)
  @packages << package
  @dependency_names |= package.dependencies
end

#deep_dependenciesObject



38
39
40
41
42
# File 'lib/cobra_commander/component.rb', line 38

def deep_dependencies
  @deep_dependencies ||= dependencies.reduce(dependencies) do |deps, dep|
    deps | dep.deep_dependencies
  end
end

#deep_dependentsObject



32
33
34
35
36
# File 'lib/cobra_commander/component.rb', line 32

def deep_dependents
  @deep_dependents ||= @umbrella.components.find_all do |dep|
    dep.deep_dependencies.include?(self)
  end
end

#dependenciesObject



50
51
52
# File 'lib/cobra_commander/component.rb', line 50

def dependencies
  @dependencies ||= @dependency_names.sort.filter_map { |name| @umbrella.find(name) }
end

#dependentsObject



44
45
46
47
48
# File 'lib/cobra_commander/component.rb', line 44

def dependents
  @dependents ||= @umbrella.components.find_all do |dep|
    dep.dependencies.include?(self)
  end
end

#describeObject



15
16
17
# File 'lib/cobra_commander/component.rb', line 15

def describe
  "#{name} (#{packages.map(&:key).join(', ')})"
end

#inspectObject



28
29
30
# File 'lib/cobra_commander/component.rb', line 28

def inspect
  "#<CobraCommander::Component:#{object_id} #{name} dependencies=#{dependencies.map(&:name)} packages=#{packages}>"
end

#root_pathsObject



24
25
26
# File 'lib/cobra_commander/component.rb', line 24

def root_paths
  @packages.map(&:path).uniq
end