Class: Omnibus::Library
- Inherits:
-
Object
- Object
- Omnibus::Library
- Includes:
- Enumerable
- Defined in:
- lib/omnibus/library.rb
Overview
Used to generate the manifest of all software components with versions
Instance Attribute Summary collapse
-
#components ⇒ Array<Omnibus::Software>
readonly
The list of Omnibus::Software definitions.
Instance Method Summary collapse
-
#build_order ⇒ Array<Omnibus::Software>
The order in which each Software component should be built.
-
#component_added(component) ⇒ void
Callback method that should be called each time an Omnibus::Software definition file is loaded.
- #each(&block) ⇒ Object
-
#initialize(project) ⇒ Library
constructor
A new instance of Library.
- #version_map ⇒ Object
Constructor Details
#initialize(project) ⇒ Library
Returns a new instance of Library.
33 34 35 36 |
# File 'lib/omnibus/library.rb', line 33 def initialize(project) @components = [] @project = project end |
Instance Attribute Details
#components ⇒ Array<Omnibus::Software> (readonly)
The list of Omnibus::Software definitions. This is populated by calling #component_added during code loading. The list is expected to be sorted in a valid order according to project and software dependencies, but this class does not verify that condition.
31 32 33 |
# File 'lib/omnibus/library.rb', line 31 def components @components end |
Instance Method Details
#build_order ⇒ Array<Omnibus::Software>
The order in which each Software component should be built. The order is based on the order of #components, optimized to move top-level dependencies later in the build order to make the git caching feature more effective. It is assumed that #components is already sorted in a valid dependency order. The optimization works as follows:
-
The first component is assumed to be a preparation step that needs to
run first, so it is not moved.
-
If a component is a top-level dependency of the project AND no other
software depends on it, it is shifted to last in the optimized order.
-
If none of the above conditions are met, the order of that component
is unchanged.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/omnibus/library.rb', line 64 def build_order head = [] tail = [] @components.each do |component| if head.length == 0 head << component elsif @project.dependencies.include?(component.name) && @components.none? { |c| c.dependencies.include?(component.name) } tail << component else head << component end end [head, tail].flatten end |
#component_added(component) ⇒ void
This method returns an undefined value.
Callback method that should be called each time an Omnibus::Software definition file is loaded.
43 44 45 46 47 |
# File 'lib/omnibus/library.rb', line 43 def component_added(component) unless @components.find { |c| c.name == component.name } @components << component end end |
#each(&block) ⇒ Object
103 104 105 |
# File 'lib/omnibus/library.rb', line 103 def each(&block) @components.each(&block) end |
#version_map ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/omnibus/library.rb', line 79 def version_map @components.reduce({}) do |map, component| map[component.name] = if component.default_version { version: component.version, default_version: component.default_version, overridden: component.overridden?, version_guid: component.version_guid, } else ## Components without a version are ## pieces of the omnibus project ## itself, and so don't really fit ## with the concept of overrides v = { version: @project.build_version } if @project.build_version.respond_to?(:git_sha) v[:version_guid] = "git:#{@project.build_version.git_sha}" end v end map end end |