groovy_oneliner 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +1 -0
- data/lib/groovy_oneliner.rb +7 -6
- data/lib/groovy_oneliner/version.rb +1 -1
- data/spec/groovy_oneliner_spec.rb +54 -8
- 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: 0b333962ce99cf8899146f1699dcca432fe061db
|
4
|
+
data.tar.gz: aec66e713ba50dd001fd7f17736f0b51c1e0e737
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a1de4d9d413b0175130f5c5224ccf2c111321769d909425f1cc6a46e9bb45ce569965a02d6b3df289c65ef7e752f335fa3576e32d3637362ffd2775b263af0f
|
7
|
+
data.tar.gz: 90d00b40574d4edbc8e93f84db6b73683b576845c87f934887caeb61e8ec612faf58bc6e04df375a980dc2891ace3f6aba80240600fbc53cb632dccb3828c01b
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# GroovyOneliner
|
2
|
+
[![Build Status](https://travis-ci.org/pedrocunha/groovy_oneliner.svg)](https://travis-ci.org/pedrocunha/groovy_oneliner?branch=master)
|
2
3
|
|
3
4
|
Convert any groovy script file to a single line script. It is recommended (and also in order for this gem to work) that all lines must be terminated with `;`.
|
4
5
|
|
data/lib/groovy_oneliner.rb
CHANGED
@@ -11,18 +11,21 @@ class GroovyOneliner
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def compute(options = {})
|
14
|
-
|
14
|
+
paths = Array(options.fetch(:path))
|
15
15
|
should_cache = options.fetch(:cache, false) || self.class.always_cache
|
16
16
|
|
17
|
+
cache_path = paths.join
|
18
|
+
|
17
19
|
if should_cache
|
18
|
-
cached_content = @cache[
|
20
|
+
cached_content = @cache[cache_path]
|
19
21
|
return cached_content if cached_content
|
20
22
|
end
|
21
23
|
|
22
|
-
content = File.read(path)
|
24
|
+
content = paths.reduce([]) { |script, path| script << File.read(path) }.join(';')
|
25
|
+
|
23
26
|
output = GroovyOneliner::Converter.new(content).compute
|
24
27
|
|
25
|
-
should_cache ? @cache[
|
28
|
+
should_cache ? @cache[cache_path] = output : output
|
26
29
|
end
|
27
30
|
|
28
31
|
def self.compute(options = {})
|
@@ -38,6 +41,4 @@ class GroovyOneliner
|
|
38
41
|
def self.always_cache
|
39
42
|
@@always_cache
|
40
43
|
end
|
41
|
-
|
42
44
|
end
|
43
|
-
|
@@ -19,21 +19,67 @@ RSpec.describe GroovyOneliner do
|
|
19
19
|
subject.compute(options)
|
20
20
|
end
|
21
21
|
|
22
|
+
context 'file contents' do
|
23
|
+
it 'returns the file contents' do
|
24
|
+
allow(File).to receive(:read).with(path).and_return("foo = 1;")
|
25
|
+
expect(subject.compute(options)).to eql('foo=1;')
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with multiple files' do
|
29
|
+
let(:path) { ['path/to/file', 'path/to/file2'] }
|
30
|
+
|
31
|
+
before do
|
32
|
+
allow(File).to receive(:read).with(path[0]).and_return("foo = 1;")
|
33
|
+
allow(File).to receive(:read).with(path[1]).and_return("bar = 2;")
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns contents with ; added in between each file content' do
|
37
|
+
expect(subject.compute(options)).to eql('foo=1;;bar=2;')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
22
42
|
context 'when caching is off' do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
43
|
+
context 'with single file' do
|
44
|
+
it 'reads the file as many times as calls to compute' do
|
45
|
+
expect(File).to receive(:read).twice.with(path).and_return("foo = 1;")
|
46
|
+
subject.compute(options)
|
47
|
+
subject.compute(options)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with multiple files' do
|
52
|
+
let(:path) { ['path/to/file', 'path/to/file2'] }
|
53
|
+
|
54
|
+
it 'reads both files as many times as calls to compute' do
|
55
|
+
expect(File).to receive(:read).twice.with(path[0]).and_return("foo = 1;")
|
56
|
+
expect(File).to receive(:read).twice.with(path[1]).and_return("foo = 1;")
|
57
|
+
subject.compute(options)
|
58
|
+
subject.compute(options)
|
59
|
+
end
|
27
60
|
end
|
28
61
|
end
|
29
62
|
|
30
63
|
context 'when caching is on' do
|
31
64
|
let(:options) { { path: path, cache: true } }
|
32
65
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
66
|
+
context 'with single file' do
|
67
|
+
it 'reads the file only once' do
|
68
|
+
expect(File).to receive(:read).once.with(path).and_return("foo = 1;")
|
69
|
+
subject.compute(options)
|
70
|
+
subject.compute(options)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'with multiple files' do
|
75
|
+
let(:path) { ['path/to/file', 'path/to/file2'] }
|
76
|
+
|
77
|
+
it 'reads both files as many times as calls to compute' do
|
78
|
+
expect(File).to receive(:read).once.with(path[0]).and_return("foo = 1;")
|
79
|
+
expect(File).to receive(:read).once.with(path[1]).and_return("foo = 1;")
|
80
|
+
subject.compute(options)
|
81
|
+
subject.compute(options)
|
82
|
+
end
|
37
83
|
end
|
38
84
|
end
|
39
85
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groovy_oneliner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Cunha
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|