travis-conditions 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/travis/conditions/v1/data.rb +10 -4
- data/lib/travis/conditions/version.rb +1 -1
- data/spec/v1/data_spec.rb +17 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 792a4640727f5262342fd6970a660617f5716c68
|
4
|
+
data.tar.gz: fe13ae1b89ad26522014b5fc95d383f09f1ca3a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1303ea01cbc8f80e19279b5e620ce82812d199f9238247b934250ba1d233497942f4bbbb02ff86a401915a8a59b9fd57e4ff32e0a9f50af742a35a410c2df3f4
|
7
|
+
data.tar.gz: 0e34fc4489a9b7ab9ee26364c64429adc830b23fd654a066041b13b1d65aab09eee3a2ce52fd8d40bf5fed8502924f536a31f291640241974f64a283b89ff57c
|
@@ -2,6 +2,9 @@ module Travis
|
|
2
2
|
module Conditions
|
3
3
|
module V1
|
4
4
|
class Data < Struct.new(:data)
|
5
|
+
PAIRS = /((?:\\.|[^= ]+)*)=("(?:\\.|[^"\\]+)*"|(?:\\.|[^ "\\]+)*)/
|
6
|
+
QUOTE = /^(["'])(.*)\1$/
|
7
|
+
|
5
8
|
def initialize(data)
|
6
9
|
super(normalize(data))
|
7
10
|
end
|
@@ -55,15 +58,18 @@ module Travis
|
|
55
58
|
when Hash
|
56
59
|
obj
|
57
60
|
else
|
58
|
-
Array(obj).map { |obj|
|
61
|
+
Array(obj).map { |obj| parse(obj.to_s) }.flatten(1).to_h
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
62
|
-
def
|
65
|
+
def parse(str)
|
63
66
|
str = str.strip
|
64
67
|
raise arg_error(str) if str.empty? || !str.include?("=")
|
65
|
-
lft, rgt
|
66
|
-
|
68
|
+
str.scan(PAIRS).map { |lft, rgt| [lft, cast(unquote(rgt))] }
|
69
|
+
end
|
70
|
+
|
71
|
+
def unquote(str)
|
72
|
+
QUOTE =~ str && $2 || str
|
67
73
|
end
|
68
74
|
|
69
75
|
def arg_error(arg)
|
data/spec/v1/data_spec.rb
CHANGED
@@ -13,9 +13,23 @@ describe Travis::Conditions::V1::Data do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
describe 'given an env array' do
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
describe 'with a single var' do
|
17
|
+
let(:env) { ['foo=FOO'] }
|
18
|
+
it { expect(subject.env(:foo)).to eq 'FOO' }
|
19
|
+
it { expect(subject.env('foo')).to eq 'FOO' }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'with several vars on one string' do
|
23
|
+
let(:env) { ['foo=FOO bar=BAR'] }
|
24
|
+
it { expect(subject.env(:foo)).to eq 'FOO' }
|
25
|
+
it { expect(subject.env(:bar)).to eq 'BAR' }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'with quoted vars' do
|
29
|
+
let(:env) { ['foo="FOO BAR" bar="BAR BAZ"'] }
|
30
|
+
it { expect(subject.env(:foo)).to eq 'FOO BAR' }
|
31
|
+
it { expect(subject.env(:bar)).to eq 'BAR BAZ' }
|
32
|
+
end
|
19
33
|
end
|
20
34
|
|
21
35
|
describe 'given a string without an = it raises an ArgumentError' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: travis-conditions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis CI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|