Class: CobraCommander::Component
- Inherits:
-
Object
- Object
- CobraCommander::Component
- Defined in:
- lib/cobra_commander/component.rb
Overview
Represents a component withing an Umbrella
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#packages ⇒ Object
readonly
Returns the value of attribute packages.
Instance Method Summary collapse
- #add_package(package) ⇒ Object
- #deep_dependencies ⇒ Object
- #deep_dependents ⇒ Object
- #dependencies ⇒ Object
- #dependents ⇒ Object
- #describe ⇒ Object
-
#initialize(umbrella, name) ⇒ Component
constructor
A new instance of Component.
- #inspect ⇒ Object
- #root_paths ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/cobra_commander/component.rb', line 6 def name @name end |
#packages ⇒ Object (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_dependencies ⇒ Object
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_dependents ⇒ Object
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 |
#dependencies ⇒ Object
50 51 52 |
# File 'lib/cobra_commander/component.rb', line 50 def dependencies @dependencies ||= @dependency_names.sort.filter_map { |name| @umbrella.find(name) } end |
#dependents ⇒ Object
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 |
#describe ⇒ Object
15 16 17 |
# File 'lib/cobra_commander/component.rb', line 15 def describe "#{name} (#{packages.map(&:key).join(', ')})" end |
#inspect ⇒ Object
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_paths ⇒ Object
24 25 26 |
# File 'lib/cobra_commander/component.rb', line 24 def root_paths @packages.map(&:path).uniq end |