vx-builder 0.0.27 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vx/builder/build_configuration/cache.rb +48 -0
- data/lib/vx/builder/build_configuration/env.rb +43 -0
- data/lib/vx/builder/build_configuration.rb +113 -0
- data/lib/vx/builder/matrix.rb +112 -0
- data/lib/vx/builder/script/env.rb +1 -1
- data/lib/vx/builder/version.rb +1 -1
- data/lib/vx/builder.rb +6 -4
- data/spec/fixtures/travis.yml +23 -13
- data/spec/lib/builder/build_configuration_spec.rb +99 -0
- data/spec/lib/builder/matrix_spec.rb +226 -0
- data/spec/support/create.rb +1 -1
- metadata +9 -9
- data/lib/vx/builder/source/constants.rb +0 -12
- data/lib/vx/builder/source/matrix.rb +0 -116
- data/lib/vx/builder/source/serializable.rb +0 -43
- data/lib/vx/builder/source.rb +0 -118
- data/spec/lib/builder/source_matrix_spec.rb +0 -222
- data/spec/lib/builder/source_spec.rb +0 -223
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe Vx::Builder::Matrix do
|
5
|
+
let(:attributes) { {
|
6
|
+
"env" => %w{ FOO=1 BAR=2 },
|
7
|
+
"rvm" => %w{ 1.8.7 1.9.3 2.0.0 },
|
8
|
+
"scala" => %w{ 2.9.2 2.10.1 },
|
9
|
+
"before_script" => "echo before_script",
|
10
|
+
"before_install" => "echo before_install",
|
11
|
+
"script" => "echo script",
|
12
|
+
} }
|
13
|
+
let(:config) { Vx::Builder::BuildConfiguration.new attributes }
|
14
|
+
let(:matrix) { described_class.new config }
|
15
|
+
|
16
|
+
subject { matrix }
|
17
|
+
|
18
|
+
context "just created" do
|
19
|
+
its(:build_configuration) { should eq config }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "keys" do
|
23
|
+
subject { matrix.keys }
|
24
|
+
|
25
|
+
it { should eq %w{ env rvm scala } }
|
26
|
+
|
27
|
+
context "without matrix" do
|
28
|
+
let(:attributes) { {} }
|
29
|
+
it { should eq [] }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'build_configurations' do
|
34
|
+
|
35
|
+
subject { matrix.build_configurations }
|
36
|
+
|
37
|
+
it { should have(12).items }
|
38
|
+
|
39
|
+
it "should copy script from source" do
|
40
|
+
expect(subject.map(&:script).flatten).to eq ["echo script"] * 12
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should copy before_script from source" do
|
44
|
+
expect(subject.map(&:before_script).flatten).to eq ["echo before_script"] * 12
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should copy before_install from source" do
|
48
|
+
expect(subject.map(&:before_install).flatten).to eq ["echo before_install"] * 12
|
49
|
+
end
|
50
|
+
|
51
|
+
context "without any matrix keys" do
|
52
|
+
let(:attributes) { {
|
53
|
+
"script" => %w{ /bin/true },
|
54
|
+
} }
|
55
|
+
|
56
|
+
it { should have(1).item }
|
57
|
+
|
58
|
+
context "attributes" do
|
59
|
+
subject { matrix.build_configurations.first.to_hash.select{|k,v| !v.empty? } }
|
60
|
+
|
61
|
+
it { should eq(
|
62
|
+
"env" => {
|
63
|
+
"matrix" => [],
|
64
|
+
"global" => []
|
65
|
+
},
|
66
|
+
"cache" => {
|
67
|
+
"directories" => [],
|
68
|
+
"enabled" => true
|
69
|
+
},
|
70
|
+
"script" => ["/bin/true"]
|
71
|
+
) }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with one :env and one :rvm key" do
|
76
|
+
let(:config) { Vx::Builder::BuildConfiguration.from_file fixture_path("travis_bug_1.yml") }
|
77
|
+
|
78
|
+
it "should have one :env and one :rvm key in matrix" do
|
79
|
+
keys = subject.map{|c| c.to_hash.select{|k,v| !v.empty? } }
|
80
|
+
expect(keys).to have(1).item
|
81
|
+
|
82
|
+
expect(keys.first["rvm"]).to eq ['2.0.0']
|
83
|
+
expect(keys.first['env']).to eq(
|
84
|
+
"matrix" => ["DB=postgresql"],
|
85
|
+
"global" => ["DB=postgresql"]
|
86
|
+
)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with :services key" do
|
91
|
+
let(:config) { Vx::Builder::BuildConfiguration.from_file fixture_path("travis_bug_2.yml") }
|
92
|
+
|
93
|
+
it "should have services in matrix" do
|
94
|
+
expect(subject).to have(1).item
|
95
|
+
expect(subject.first.services).to eq ['elasticsearch']
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "attributes" do
|
100
|
+
subject { matrix.build_configurations.map(&:matrix_id) }
|
101
|
+
|
102
|
+
it "should have true values" do
|
103
|
+
expect(subject).to eq [
|
104
|
+
"env:BAR=2, rvm:1.8.7, scala:2.10.1",
|
105
|
+
"env:FOO=1, rvm:1.8.7, scala:2.10.1",
|
106
|
+
"env:BAR=2, rvm:1.8.7, scala:2.9.2",
|
107
|
+
"env:FOO=1, rvm:1.8.7, scala:2.9.2",
|
108
|
+
"env:BAR=2, rvm:1.9.3, scala:2.10.1",
|
109
|
+
"env:FOO=1, rvm:1.9.3, scala:2.10.1",
|
110
|
+
"env:BAR=2, rvm:1.9.3, scala:2.9.2",
|
111
|
+
"env:FOO=1, rvm:1.9.3, scala:2.9.2",
|
112
|
+
"env:BAR=2, rvm:2.0.0, scala:2.10.1",
|
113
|
+
"env:FOO=1, rvm:2.0.0, scala:2.10.1",
|
114
|
+
"env:BAR=2, rvm:2.0.0, scala:2.9.2",
|
115
|
+
"env:FOO=1, rvm:2.0.0, scala:2.9.2"
|
116
|
+
]
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with one matrix key" do
|
120
|
+
let(:attributes) { {
|
121
|
+
"rvm" => %w{ 2.0.0 },
|
122
|
+
} }
|
123
|
+
|
124
|
+
it { should eq ['rvm:2.0.0'] }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "attributes_for_new_confgurations_with_merged_env" do
|
130
|
+
subject { matrix.attributes_for_new_build_configurations_with_merged_env }
|
131
|
+
|
132
|
+
before do
|
133
|
+
attributes.merge!(
|
134
|
+
"env" => {
|
135
|
+
"global" => "FOO=1",
|
136
|
+
"matrix" => %w{ BAR=1 BAR=2 }
|
137
|
+
}
|
138
|
+
)
|
139
|
+
end
|
140
|
+
|
141
|
+
it { should have(12).items }
|
142
|
+
|
143
|
+
it "should merge matrix env to global env" do
|
144
|
+
expect(subject.map{|i| i["env"]["global"] }.uniq.sort).to eq([["BAR=1", "FOO=1"], ["BAR=2", "FOO=1"]])
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'attributes_for_new_build_configurations' do
|
149
|
+
subject { matrix.attributes_for_new_build_configurations }
|
150
|
+
|
151
|
+
it { should have(12).items }
|
152
|
+
|
153
|
+
its(:first) { should eq("rvm" => "1.8.7",
|
154
|
+
"scala" => "2.10.1",
|
155
|
+
"env" => "BAR=2") }
|
156
|
+
its(:last) { should eq("rvm" => "2.0.0",
|
157
|
+
"scala" => "2.9.2",
|
158
|
+
"env" => "FOO=1") }
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'extract_keys_from_builds_configuration' do
|
162
|
+
subject { matrix.extract_keys_from_builds_configuration }
|
163
|
+
it {
|
164
|
+
should eq [
|
165
|
+
["rvm", %w{ 1.8.7 1.9.3 2.0.0 }],
|
166
|
+
["scala", %w{ 2.9.2 2.10.1 }],
|
167
|
+
["env", %w{ FOO=1 BAR=2 }]
|
168
|
+
]
|
169
|
+
}
|
170
|
+
end
|
171
|
+
|
172
|
+
context "permutate_and_build_pairs" do
|
173
|
+
subject { format_values matrix.permutate_and_build_pairs }
|
174
|
+
let(:expected) { [
|
175
|
+
%w{env:BAR=2 rvm:1.8.7 scala:2.10.1},
|
176
|
+
%w{env:BAR=2 rvm:1.8.7 scala:2.9.2},
|
177
|
+
%w{env:BAR=2 rvm:1.9.3 scala:2.10.1},
|
178
|
+
%w{env:BAR=2 rvm:1.9.3 scala:2.9.2},
|
179
|
+
%w{env:BAR=2 rvm:2.0.0 scala:2.10.1},
|
180
|
+
%w{env:BAR=2 rvm:2.0.0 scala:2.9.2},
|
181
|
+
%w{env:FOO=1 rvm:1.8.7 scala:2.10.1},
|
182
|
+
%w{env:FOO=1 rvm:1.8.7 scala:2.9.2},
|
183
|
+
%w{env:FOO=1 rvm:1.9.3 scala:2.10.1},
|
184
|
+
%w{env:FOO=1 rvm:1.9.3 scala:2.9.2},
|
185
|
+
%w{env:FOO=1 rvm:2.0.0 scala:2.10.1},
|
186
|
+
%w{env:FOO=1 rvm:2.0.0 scala:2.9.2},
|
187
|
+
] }
|
188
|
+
|
189
|
+
it { should eq expected }
|
190
|
+
|
191
|
+
context "with empty keys" do
|
192
|
+
let(:attributes) { {
|
193
|
+
"env" => %w{ FOO=1 BAR=2 },
|
194
|
+
"rvm" => %w{ 1.8.7 1.9.3 2.0.0 },
|
195
|
+
"scala" => %w{ 2.9.2 2.10.1 },
|
196
|
+
"java" => [],
|
197
|
+
} }
|
198
|
+
it { should eq expected }
|
199
|
+
end
|
200
|
+
|
201
|
+
context "with one key" do
|
202
|
+
let(:attributes) { {
|
203
|
+
"rvm" => %w{ 1.9.3 2.0.0 },
|
204
|
+
} }
|
205
|
+
let(:expected) {[
|
206
|
+
%w{ rvm:1.9.3 },
|
207
|
+
%w{ rvm:2.0.0 }
|
208
|
+
]}
|
209
|
+
it { should eq expected }
|
210
|
+
end
|
211
|
+
|
212
|
+
context "without matrix" do
|
213
|
+
let(:attributes) { {
|
214
|
+
"rvm" => %w{ 2.0.0 },
|
215
|
+
} }
|
216
|
+
let(:expected) {[
|
217
|
+
%w{ rvm:2.0.0 }
|
218
|
+
]}
|
219
|
+
it { should eq expected }
|
220
|
+
end
|
221
|
+
|
222
|
+
def format_values(values)
|
223
|
+
values.map{|i| i.map(&:to_s).sort }.sort
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
data/spec/support/create.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vx-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Galinsky
|
@@ -123,9 +123,13 @@ files:
|
|
123
123
|
- README.md
|
124
124
|
- Rakefile
|
125
125
|
- lib/vx/builder.rb
|
126
|
+
- lib/vx/builder/build_configuration.rb
|
127
|
+
- lib/vx/builder/build_configuration/cache.rb
|
128
|
+
- lib/vx/builder/build_configuration/env.rb
|
126
129
|
- lib/vx/builder/configuration.rb
|
127
130
|
- lib/vx/builder/helper/config.rb
|
128
131
|
- lib/vx/builder/helper/trace_sh_command.rb
|
132
|
+
- lib/vx/builder/matrix.rb
|
129
133
|
- lib/vx/builder/script.rb
|
130
134
|
- lib/vx/builder/script/cache.rb
|
131
135
|
- lib/vx/builder/script/clojure.rb
|
@@ -136,10 +140,6 @@ files:
|
|
136
140
|
- lib/vx/builder/script/scala.rb
|
137
141
|
- lib/vx/builder/script/script.rb
|
138
142
|
- lib/vx/builder/script/services.rb
|
139
|
-
- lib/vx/builder/source.rb
|
140
|
-
- lib/vx/builder/source/constants.rb
|
141
|
-
- lib/vx/builder/source/matrix.rb
|
142
|
-
- lib/vx/builder/source/serializable.rb
|
143
143
|
- lib/vx/builder/task.rb
|
144
144
|
- lib/vx/builder/version.rb
|
145
145
|
- spec/fixtures/clojure.yml
|
@@ -147,7 +147,9 @@ files:
|
|
147
147
|
- spec/fixtures/travis.yml
|
148
148
|
- spec/fixtures/travis_bug_1.yml
|
149
149
|
- spec/fixtures/travis_bug_2.yml
|
150
|
+
- spec/lib/builder/build_configuration_spec.rb
|
150
151
|
- spec/lib/builder/configuration_spec.rb
|
152
|
+
- spec/lib/builder/matrix_spec.rb
|
151
153
|
- spec/lib/builder/script/cache_spec.rb
|
152
154
|
- spec/lib/builder/script/clojure_spec.rb
|
153
155
|
- spec/lib/builder/script/env_spec.rb
|
@@ -156,8 +158,6 @@ files:
|
|
156
158
|
- spec/lib/builder/script/ruby_spec.rb
|
157
159
|
- spec/lib/builder/script/scala_spec.rb
|
158
160
|
- spec/lib/builder/script_spec.rb
|
159
|
-
- spec/lib/builder/source_matrix_spec.rb
|
160
|
-
- spec/lib/builder/source_spec.rb
|
161
161
|
- spec/lib/builder/task_spec.rb
|
162
162
|
- spec/lib/builder_spec.rb
|
163
163
|
- spec/spec_helper.rb
|
@@ -194,7 +194,9 @@ test_files:
|
|
194
194
|
- spec/fixtures/travis.yml
|
195
195
|
- spec/fixtures/travis_bug_1.yml
|
196
196
|
- spec/fixtures/travis_bug_2.yml
|
197
|
+
- spec/lib/builder/build_configuration_spec.rb
|
197
198
|
- spec/lib/builder/configuration_spec.rb
|
199
|
+
- spec/lib/builder/matrix_spec.rb
|
198
200
|
- spec/lib/builder/script/cache_spec.rb
|
199
201
|
- spec/lib/builder/script/clojure_spec.rb
|
200
202
|
- spec/lib/builder/script/env_spec.rb
|
@@ -203,8 +205,6 @@ test_files:
|
|
203
205
|
- spec/lib/builder/script/ruby_spec.rb
|
204
206
|
- spec/lib/builder/script/scala_spec.rb
|
205
207
|
- spec/lib/builder/script_spec.rb
|
206
|
-
- spec/lib/builder/source_matrix_spec.rb
|
207
|
-
- spec/lib/builder/source_spec.rb
|
208
208
|
- spec/lib/builder/task_spec.rb
|
209
209
|
- spec/lib/builder_spec.rb
|
210
210
|
- spec/spec_helper.rb
|
@@ -1,116 +0,0 @@
|
|
1
|
-
module Vx
|
2
|
-
module Builder
|
3
|
-
class Source
|
4
|
-
class Matrix
|
5
|
-
|
6
|
-
KEYS = (Source::LANGS + %w{ gemfile matrix_env:env image }).freeze
|
7
|
-
NOT_MATRIX_KEYS = %w{
|
8
|
-
script before_script services before_install
|
9
|
-
after_success
|
10
|
-
}
|
11
|
-
|
12
|
-
attr_reader :source
|
13
|
-
|
14
|
-
def initialize(build_configuration)
|
15
|
-
@source = build_configuration
|
16
|
-
end
|
17
|
-
|
18
|
-
def keys
|
19
|
-
extract_pair_of_key_and_values.map(&:first).sort
|
20
|
-
end
|
21
|
-
|
22
|
-
def configurations
|
23
|
-
attributes_for_new_configurations_with_merged_env.map do |attrs|
|
24
|
-
attrs = attrs.merge(
|
25
|
-
NOT_MATRIX_KEYS.inject({}) do |a,v|
|
26
|
-
a[v] = source.public_send(v)
|
27
|
-
a
|
28
|
-
end
|
29
|
-
)
|
30
|
-
Source.new attrs
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def attributes_for_new_configurations_with_merged_env
|
35
|
-
attrs = attributes_for_new_configurations
|
36
|
-
attrs = [{}] if attrs.empty?
|
37
|
-
attrs.map do |a|
|
38
|
-
e = a["env"]
|
39
|
-
a["env"] = {
|
40
|
-
"global" => Array(e) + source.global_env,
|
41
|
-
"matrix" => e
|
42
|
-
}
|
43
|
-
a
|
44
|
-
end
|
45
|
-
attrs
|
46
|
-
end
|
47
|
-
|
48
|
-
def attributes_for_new_configurations
|
49
|
-
permutate_and_build_values.inject([]) do |ac, values|
|
50
|
-
ac << values.inject({}) do |a,val|
|
51
|
-
a[val.key] = val.value
|
52
|
-
a
|
53
|
-
end
|
54
|
-
ac
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def permutate_and_build_values
|
59
|
-
values = extract_pair_of_key_and_values.map do |key, vals|
|
60
|
-
vals.map{|it| Value.new(key, it) }
|
61
|
-
end
|
62
|
-
if matrix_values?(values)
|
63
|
-
array_permutations(values).map do |it|
|
64
|
-
if it.is_a?(Array)
|
65
|
-
it.flatten
|
66
|
-
else
|
67
|
-
[it]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
else
|
71
|
-
[values.flatten]
|
72
|
-
end.sort_by(&:to_s)
|
73
|
-
end
|
74
|
-
|
75
|
-
def extract_pair_of_key_and_values
|
76
|
-
KEYS.map.inject([]) do |a, k|
|
77
|
-
k_method, k_name = k.split(":")
|
78
|
-
k_name ||= k_method
|
79
|
-
|
80
|
-
if (val = source[k_method]) && !val.empty?
|
81
|
-
a << [k_name, val]
|
82
|
-
end
|
83
|
-
a
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
def matrix_values?(values)
|
90
|
-
!values.all?{|i| i.size == 1 }
|
91
|
-
end
|
92
|
-
|
93
|
-
def array_permutations array, index=0
|
94
|
-
# index is 0 by default : start at the beginning, more elegant.
|
95
|
-
return array[-1] if index == array.size - 1 # Return last element if at end.
|
96
|
-
|
97
|
-
result = []
|
98
|
-
|
99
|
-
array[index].each do |element| # For each array
|
100
|
-
array_permutations(array, index + 1).each do |x| # Permute permute permute
|
101
|
-
result << [element, x]
|
102
|
-
end
|
103
|
-
end
|
104
|
-
result
|
105
|
-
end
|
106
|
-
|
107
|
-
Value = Struct.new(:key, :value) do
|
108
|
-
def to_s
|
109
|
-
[key, value].join(":")
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module Vx
|
5
|
-
module Builder
|
6
|
-
class Source
|
7
|
-
|
8
|
-
module Serializable
|
9
|
-
|
10
|
-
def self.included(base)
|
11
|
-
base.extend ClassMethods
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_yaml
|
15
|
-
YAML.dump(attributes)
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_hash
|
19
|
-
attributes
|
20
|
-
end
|
21
|
-
|
22
|
-
module ClassMethods
|
23
|
-
|
24
|
-
def from_file(file)
|
25
|
-
if File.readable? file
|
26
|
-
from_yaml File.read(file)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def from_yaml(yaml)
|
31
|
-
from_attributes YAML.load(yaml)
|
32
|
-
end
|
33
|
-
|
34
|
-
def from_attributes(attrs)
|
35
|
-
Source.new attrs
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/vx/builder/source.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
require File.expand_path("../source/constants", __FILE__)
|
2
|
-
require File.expand_path("../source/matrix", __FILE__)
|
3
|
-
require File.expand_path("../source/serializable", __FILE__)
|
4
|
-
|
5
|
-
module Vx
|
6
|
-
module Builder
|
7
|
-
class Source
|
8
|
-
|
9
|
-
include Source::Serializable
|
10
|
-
|
11
|
-
attr_reader :attributes
|
12
|
-
alias_method :to_hash, :attributes
|
13
|
-
|
14
|
-
def initialize(attrs = {})
|
15
|
-
@attributes = normalize_attributes attrs
|
16
|
-
end
|
17
|
-
|
18
|
-
def [](val)
|
19
|
-
public_send(val)
|
20
|
-
end
|
21
|
-
|
22
|
-
def matrix_keys
|
23
|
-
@matrix_keys ||=
|
24
|
-
Matrix::KEYS.inject({}) do |a,k|
|
25
|
-
k_method, k_name = k.split(":")
|
26
|
-
k_name ||= k_method
|
27
|
-
val = send(k_method)
|
28
|
-
unless val.empty?
|
29
|
-
a[k_name] = val.first
|
30
|
-
end
|
31
|
-
a
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_matrix_s
|
36
|
-
@to_matrix_s ||= matrix_keys.map{|k,v| "#{k}:#{v}" }.sort.join(", ")
|
37
|
-
end
|
38
|
-
|
39
|
-
def to_script_builder(build)
|
40
|
-
ScriptBuilder.new(build, self)
|
41
|
-
end
|
42
|
-
|
43
|
-
def env
|
44
|
-
attributes["env"]
|
45
|
-
end
|
46
|
-
|
47
|
-
def matrix_env
|
48
|
-
attributes["env"]["matrix"]
|
49
|
-
end
|
50
|
-
|
51
|
-
def global_env
|
52
|
-
attributes["env"]["global"]
|
53
|
-
end
|
54
|
-
|
55
|
-
def cached_directories
|
56
|
-
if attributes["cache"] == false
|
57
|
-
false
|
58
|
-
else
|
59
|
-
(attributes["cache"] && attributes["cache"]["directories"]) || []
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def language
|
64
|
-
attributes["language"]
|
65
|
-
end
|
66
|
-
|
67
|
-
AS_ARRAY.each do |m|
|
68
|
-
define_method m do
|
69
|
-
@attributes[m] || []
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def merge(attrs = {})
|
74
|
-
self.class.from_attributes self.attributes.merge(attrs)
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def normalize_attributes(attributes)
|
80
|
-
attributes = attributes.inject({}) do |a,row|
|
81
|
-
k,v = row
|
82
|
-
if AS_ARRAY.include?(k.to_s)
|
83
|
-
v = Array(v)
|
84
|
-
end
|
85
|
-
a[k.to_s] = v
|
86
|
-
a
|
87
|
-
end
|
88
|
-
normalize_env_attribute attributes
|
89
|
-
end
|
90
|
-
|
91
|
-
def normalize_env_attribute(attributes)
|
92
|
-
env = (attributes['env'] || {}) .dup
|
93
|
-
case env
|
94
|
-
when Hash
|
95
|
-
attributes["env"] = {
|
96
|
-
"matrix" => Array(env['matrix']),
|
97
|
-
"global" => Array(env['global'])
|
98
|
-
}
|
99
|
-
else
|
100
|
-
attributes['env'] = {
|
101
|
-
"matrix" => Array(env).map(&:to_s),
|
102
|
-
"global" => []
|
103
|
-
}
|
104
|
-
end
|
105
|
-
freeze_normalized_attributes attributes
|
106
|
-
end
|
107
|
-
|
108
|
-
def freeze_normalized_attributes(attributes)
|
109
|
-
attributes.freeze
|
110
|
-
attributes['env'].freeze
|
111
|
-
attributes['env']['global'].freeze
|
112
|
-
attributes['env']['matrix'].freeze
|
113
|
-
attributes
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|