Class: Omnibus::Library

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/omnibus/library.rb

Overview

Used to generate the manifest of all software components with versions

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

Returns:

See Also:

  • Omnibus.expand_software


31
32
33
# File 'lib/omnibus/library.rb', line 31

def components
  @components
end

Instance Method Details

#build_orderArray<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:

  1. The first component is assumed to be a preparation step that needs to

run first, so it is not moved.

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

  1. If none of the above conditions are met, the order of that component

is unchanged.

Returns:



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.

Parameters:



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_mapObject



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