Class: Vx::Builder::Source::Matrix
- Inherits:
-
Object
- Object
- Vx::Builder::Source::Matrix
- Defined in:
- lib/vx/builder/source/matrix.rb
Defined Under Namespace
Classes: Value
Constant Summary collapse
- KEYS =
(Source::LANGS + %w{ matrix_env:env }).freeze
- NOT_MATRIX_KEYS =
%w{ script before_script services }
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #attributes_for_new_configurations ⇒ Object
- #attributes_for_new_configurations_with_merged_env ⇒ Object
- #configurations ⇒ Object
- #extract_pair_of_key_and_values ⇒ Object
-
#initialize(build_configuration) ⇒ Matrix
constructor
A new instance of Matrix.
- #keys ⇒ Object
- #permutate_and_build_values ⇒ Object
Constructor Details
#initialize(build_configuration) ⇒ Matrix
Returns a new instance of Matrix.
11 12 13 |
# File 'lib/vx/builder/source/matrix.rb', line 11 def initialize(build_configuration) @source = build_configuration end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/vx/builder/source/matrix.rb', line 9 def source @source end |
Instance Method Details
#attributes_for_new_configurations ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/vx/builder/source/matrix.rb', line 45 def attributes_for_new_configurations permutate_and_build_values.inject([]) do |ac, values| ac << values.inject({}) do |a,val| a[val.key] = val.value a end ac end end |
#attributes_for_new_configurations_with_merged_env ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vx/builder/source/matrix.rb', line 31 def attributes_for_new_configurations_with_merged_env attrs = attributes_for_new_configurations attrs = [{}] if attrs.empty? attrs.map do |a| e = a["env"] a["env"] = { "global" => Array(e) + source.global_env, "matrix" => e } a end attrs end |
#configurations ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vx/builder/source/matrix.rb', line 19 def configurations attributes_for_new_configurations_with_merged_env.map do |attrs| attrs = attrs.merge( NOT_MATRIX_KEYS.inject({}) do |a,v| a[v] = source.public_send(v) a end ) Source.new attrs end end |
#extract_pair_of_key_and_values ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vx/builder/source/matrix.rb', line 72 def extract_pair_of_key_and_values KEYS.map.inject([]) do |a, k| k_method, k_name = k.split(":") k_name ||= k_method if (val = source[k_method]) && !val.empty? a << [k_name, val] end a end end |
#keys ⇒ Object
15 16 17 |
# File 'lib/vx/builder/source/matrix.rb', line 15 def keys extract_pair_of_key_and_values.map(&:first).sort end |
#permutate_and_build_values ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vx/builder/source/matrix.rb', line 55 def permutate_and_build_values values = extract_pair_of_key_and_values.map do |key, vals| vals.map{|it| Value.new(key, it) } end if matrix_values?(values) array_permutations(values).map do |it| if it.is_a?(Array) it.flatten else [it] end end else [values.flatten] end.sort_by(&:to_s) end |