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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: becb9184b8f80f893eacae6964412b6a68436292
4
- data.tar.gz: feb97a340c04d053cb700d177dcdbb8c68b277f6
3
+ metadata.gz: 0b333962ce99cf8899146f1699dcca432fe061db
4
+ data.tar.gz: aec66e713ba50dd001fd7f17736f0b51c1e0e737
5
5
  SHA512:
6
- metadata.gz: 04a64e75d13f1b0f271a697595209fa48664d17497c38dbaa85e8735f037ef9557414bc0b8cb80d76d5d378335199b8d97329af8af4ec9cb79fc29560643fa81
7
- data.tar.gz: ac765a3f0f7aa37a6e56753b41eaed69677f6acd163a38512c198987e7c5b9aa4851396074295212d854fe51b3e8aa4e0f8c12df5ad6df56a13de886e12066a2
6
+ metadata.gz: 8a1de4d9d413b0175130f5c5224ccf2c111321769d909425f1cc6a46e9bb45ce569965a02d6b3df289c65ef7e752f335fa3576e32d3637362ffd2775b263af0f
7
+ data.tar.gz: 90d00b40574d4edbc8e93f84db6b73683b576845c87f934887caeb61e8ec612faf58bc6e04df375a980dc2891ace3f6aba80240600fbc53cb632dccb3828c01b
data/.travis.yml CHANGED
@@ -2,5 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1.0
4
4
  - 2.1.1
5
+ - 2.2.0
5
6
  script:
6
7
  - 'bundle exec rspec'
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
 
@@ -11,18 +11,21 @@ class GroovyOneliner
11
11
  end
12
12
 
13
13
  def compute(options = {})
14
- path = options.fetch(:path)
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[path]
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[path] = output : output
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
-
@@ -1,3 +1,3 @@
1
1
  class GroovyOneliner
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -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
- it 'reads the file as many times as calls to compute' do
24
- expect(File).to receive(:read).twice.with(path).and_return("foo = 1;")
25
- subject.compute(options)
26
- subject.compute(options)
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
- it 'reads the file only once' do
34
- expect(File).to receive(:read).once.with(path).and_return("foo = 1;")
35
- subject.compute(options)
36
- subject.compute(options)
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.2.0
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: 2014-12-10 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler