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

#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.

Yield Parameters:

  • env (Hash{String => String})

    merged env vars for the command

Returns:

  • the value returned by the block



36
37
38
# File 'lib/cobra_commander/component.rb', line 36

def around_command(&)
  nest_sources(@packages.map(&:source).uniq, {}, &)
end

#deep_dependenciesObject



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_dependentsObject



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

#dependenciesObject



62
63
64
# File 'lib/cobra_commander/component.rb', line 62

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

#dependentsObject



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

#describeObject



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

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

#inspectObject



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_pathsObject



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

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