lib/evrone/ci/router/build_matrix.rb in evrone-ci-router-0.2.0.pre3 vs lib/evrone/ci/router/build_matrix.rb in evrone-ci-router-0.2.0.pre4

- old
+ new

@@ -1,11 +1,11 @@ module Evrone module CI class Router class BuildMatrix - KEYS = (Travis::LANGS + %w{ env }).freeze + KEYS = (Travis::LANGS + %w{ matrix_env:env }).freeze NOT_MATRIX_KEYS = %w{ script before_script } attr_reader :travis def initialize(travis) @@ -15,20 +15,34 @@ def keys extract_pair_of_key_and_values.map(&:first).sort end def travises - attributes_for_new_travises.map do |attrs| - Travis.new attrs.merge( + attributes_for_new_travises_with_merged_env.map do |attrs| + attrs = attrs.merge( NOT_MATRIX_KEYS.inject({}) do |a,v| a[v] = travis.public_send(v) a end ) + Travis.new attrs end end + def attributes_for_new_travises_with_merged_env + attrs = attributes_for_new_travises + attrs.map do |a| + e = a["env"] + a["env"] = { + "global" => Array(e) + travis.global_env, + "matrix" => e + } + a + end + attrs + end + def attributes_for_new_travises permutate_and_build_values.inject([]) do |ac, values| ac << values.inject({}) do |a,val| a[val.key] = val.value a @@ -54,11 +68,14 @@ end.sort_by(&:to_s) end def extract_pair_of_key_and_values KEYS.map.inject([]) do |a, k| - if (val = travis[k]) && !val.empty? - a << [k, val] + k_method, k_name = k.split(":") + k_name ||= k_method + + if (val = travis[k_method]) && !val.empty? + a << [k_name, val] end a end end