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
-
#around_command {|env| ... } ⇒ Object
Wraps the execution of a command on this component by nesting the around_command of each distinct source backing its packages, so every package gets a chance to enhance the surrounding process.
- #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 |
#around_command {|env| ... } ⇒ Object
Wraps the execution of a command on this component by nesting the around_command of each distinct source backing its packages, so every package gets a chance to enhance the surrounding process. The env vars each source yields are merged (later sources win) and the merged hash is yielded to the block.
36 37 38 |
# File 'lib/cobra_commander/component.rb', line 36 def around_command(&) nest_sources(@packages.map(&:source).uniq, {}, &) end |
#deep_dependencies ⇒ Object
50 51 52 53 54 |
# File 'lib/cobra_commander/component.rb', line 50 def deep_dependencies @deep_dependencies ||= dependencies.reduce(dependencies) do |deps, dep| deps | dep.deep_dependencies end end |
#deep_dependents ⇒ Object
44 45 46 47 48 |
# File 'lib/cobra_commander/component.rb', line 44 def deep_dependents @deep_dependents ||= @umbrella.components.find_all do |dep| dep.deep_dependencies.include?(self) end end |
#dependencies ⇒ Object
62 63 64 |
# File 'lib/cobra_commander/component.rb', line 62 def dependencies @dependencies ||= @dependency_names.sort.filter_map { |name| @umbrella.find(name) } end |
#dependents ⇒ Object
56 57 58 59 60 |
# File 'lib/cobra_commander/component.rb', line 56 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
40 41 42 |
# File 'lib/cobra_commander/component.rb', line 40 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 |