Class: RightScale::CookbookSequence
- Includes:
- Serializable
- Defined in:
- lib/right_agent/core_payload_types/cookbook_sequence.rb
Overview
Sequence of cookbooks and where to put them.
Instance Attribute Summary collapse
-
#hash ⇒ Object
(String) Hash for the repository this came from.
-
#paths ⇒ Object
(Array) relative cookbook paths to use from the repository root.
-
#positions ⇒ Object
(Array) CookbookPosition objects for each cookbook.
Instance Method Summary collapse
-
#initialize(*args) ⇒ CookbookSequence
constructor
Initialize fields from given arguments.
-
#serialized_members ⇒ Object
Array of serialized fields given to constructor.
-
#sort_by_path! ⇒ Object
Reorder @positions so it respects @path.
Methods included from Serializable
Constructor Details
#initialize(*args) ⇒ CookbookSequence
Initialize fields from given arguments
37 38 39 40 41 |
# File 'lib/right_agent/core_payload_types/cookbook_sequence.rb', line 37 def initialize(*args) @paths = args[0] @positions = args[1] if args.size > 1 @hash = args[2] if args.size > 2 end |
Instance Attribute Details
#hash ⇒ Object
(String) Hash for the repository this came from
34 35 36 |
# File 'lib/right_agent/core_payload_types/cookbook_sequence.rb', line 34 def hash @hash end |
#paths ⇒ Object
(Array) relative cookbook paths to use from the repository root.
30 31 32 |
# File 'lib/right_agent/core_payload_types/cookbook_sequence.rb', line 30 def paths @paths end |
#positions ⇒ Object
(Array) CookbookPosition objects for each cookbook.
32 33 34 |
# File 'lib/right_agent/core_payload_types/cookbook_sequence.rb', line 32 def positions @positions end |
Instance Method Details
#serialized_members ⇒ Object
Array of serialized fields given to constructor
44 45 46 |
# File 'lib/right_agent/core_payload_types/cookbook_sequence.rb', line 44 def serialized_members [ @paths, @positions, @hash ] end |
#sort_by_path! ⇒ Object
Reorder @positions so it respects @path. The comparison rule is as follows:
-
for two pairs of cookbooks [a_pos, a_cookbook], [b_pos, b_cookbook]
-
let a_index be the index of the first element of cookbooks_path that is a prefix for a_pos.
-
let b_index be similarly defined on b_pos.
-
if a_index != b_index, sort on a_index and b_index.
-
otherwise lexically sort on a_pos and b_pos.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/right_agent/core_payload_types/cookbook_sequence.rb', line 55 def sort_by_path! indices = @positions.map {|a| @paths.index(@paths.find {|p| a.position.start_with? p}) } @positions = indices.zip(@positions).sort {|a, b| aindex, acb = a bindex, bcb = b if aindex == bindex acb.position <=> bcb.position else aindex <=> bindex end }.map {|p| p.last} end |