groovy_oneliner 1.0.0 → 1.1.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: b8dc13200f769f7b66bd2b61badef306f15d2a16
4
- data.tar.gz: 5a80d432721ab5a87f406da1312c42c1765c7c4e
3
+ metadata.gz: 5d318fc216012756da8687ec71f1a7f8454246b6
4
+ data.tar.gz: c80ee2b0e416668a5a272bd398886412d5ee70c9
5
5
  SHA512:
6
- metadata.gz: b5317e989aa0498890c3d93d59b8e11503874c5d48a0594ff348d49be60802153e47bf93685306ca2527159ac01260a534e25ca50c6d73a105af91f94dccdf62
7
- data.tar.gz: 2ba1bb414ae2d252e65c167286b918b8932203f0d687484e0b6cd973a3fd12d3c8ef58dbd14f4728965218928731c96deeabf9076cc7e4d95bd92a73c537ed6e
6
+ metadata.gz: 4fe72e995977a35e1aa9c8eb1edf4aa61f3658d31437532a340642a463933388979dd9c84794d1dc05c00d3ae05c6f340ba9ba3f6f7e5fa2c07596b265b940d2
7
+ data.tar.gz: 1c41cea35991ee25f034e2f0017dbc2c80187caec1f042e5c53f93834c7cca24eb27735fa88e4fcb1a850c93477a166dbe7100c90a052171d57ceb895255f00a
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.1.1
5
+ script:
6
+ - 'bundle exec rspec'
data/README.md CHANGED
@@ -35,7 +35,7 @@ b = 2;
35
35
 
36
36
  Converts to
37
37
  ```groovy
38
- a = 1; b = 2;
38
+ a = 1;b = 2;
39
39
  ```
40
40
 
41
41
  ## Installation
@@ -57,13 +57,19 @@ Or install it yourself as:
57
57
  ## Usage
58
58
 
59
59
  ```
60
- GroovyOneliner.compute(file: 'path/to/file')
60
+ GroovyOneliner.compute(path: 'path/to/file')
61
61
  ```
62
62
 
63
63
  If you want to cache reading the file (recommended for production & staging environments)
64
64
 
65
65
  ```
66
- GroovyOneliner.compute(file: 'path/to/file', cache: true)
66
+ GroovyOneliner.compute(path: 'path/to/file', cache: true)
67
+ ```
68
+
69
+ You can also set the cache at class level
70
+ ```
71
+ GroovyOneliner.always_cache = true
72
+ GroovyOneliner.compute(path: 'path/to/file')
67
73
  ```
68
74
 
69
75
  ## Contributing
@@ -12,7 +12,7 @@ class GroovyOneliner
12
12
 
13
13
  def compute(options = {})
14
14
  path = options.fetch(:path)
15
- should_cache = options.fetch(:cache, false)
15
+ should_cache = options.fetch(:cache, false) || self.class.always_cache
16
16
 
17
17
  if should_cache
18
18
  cached_content = @cache[path]
@@ -29,5 +29,15 @@ class GroovyOneliner
29
29
  self.instance.compute(options)
30
30
  end
31
31
 
32
+ @@always_cache = false
33
+
34
+ def self.always_cache=(value)
35
+ @@always_cache = value
36
+ end
37
+
38
+ def self.always_cache
39
+ @@always_cache
40
+ end
41
+
32
42
  end
33
43
 
@@ -1,3 +1,3 @@
1
1
  class GroovyOneliner
2
- VERSION = "1.0.0"
2
+ VERSION = '1.1.0'
3
3
  end
@@ -11,6 +11,7 @@ RSpec.describe GroovyOneliner do
11
11
  let(:path) { 'path/to/file' }
12
12
  let(:options) { { path: path } }
13
13
 
14
+ before { Singleton.__init__(GroovyOneliner) }
14
15
  subject { described_class }
15
16
 
16
17
  it 'allows to compute a file' do
@@ -36,6 +37,18 @@ RSpec.describe GroovyOneliner do
36
37
  end
37
38
  end
38
39
 
40
+ context 'when caching is on through the class variable' do
41
+ before { described_class.always_cache = true }
42
+
43
+ it 'reads the file only once' do
44
+ expect(File).to receive(:read).once.with(path).and_return("foo = 1;")
45
+ subject.compute(options)
46
+ subject.compute(options)
47
+ end
48
+
49
+ after { described_class.always_cache = false }
50
+ end
51
+
39
52
  end
40
53
 
41
54
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groovy_oneliner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Cunha
@@ -117,6 +117,7 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
119
  - ".rspec"
120
+ - ".travis.yml"
120
121
  - Gemfile
121
122
  - Guardfile
122
123
  - LICENSE.txt