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 +4 -4
- data/.travis.yml +6 -0
- data/README.md +9 -3
- data/lib/groovy_oneliner.rb +11 -1
- data/lib/groovy_oneliner/version.rb +1 -1
- data/spec/groovy_oneliner_spec.rb +13 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d318fc216012756da8687ec71f1a7f8454246b6
|
4
|
+
data.tar.gz: c80ee2b0e416668a5a272bd398886412d5ee70c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fe72e995977a35e1aa9c8eb1edf4aa61f3658d31437532a340642a463933388979dd9c84794d1dc05c00d3ae05c6f340ba9ba3f6f7e5fa2c07596b265b940d2
|
7
|
+
data.tar.gz: 1c41cea35991ee25f034e2f0017dbc2c80187caec1f042e5c53f93834c7cca24eb27735fa88e4fcb1a850c93477a166dbe7100c90a052171d57ceb895255f00a
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -35,7 +35,7 @@ b = 2;
|
|
35
35
|
|
36
36
|
Converts to
|
37
37
|
```groovy
|
38
|
-
a = 1;
|
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(
|
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(
|
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
|
data/lib/groovy_oneliner.rb
CHANGED
@@ -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
|
|
@@ -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.
|
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
|