Class: GroovyOneliner
- Inherits:
-
Object
show all
- Includes:
- Singleton
- Defined in:
- lib/groovy_oneliner.rb,
lib/groovy_oneliner/cache.rb,
lib/groovy_oneliner/version.rb,
lib/groovy_oneliner/converter.rb
Defined Under Namespace
Classes: Cache, Converter
Constant Summary
collapse
- VERSION =
'1.3.0'
- @@always_cache =
false
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GroovyOneliner.
Class Method Details
.always_cache ⇒ Object
41
42
43
|
# File 'lib/groovy_oneliner.rb', line 41
def self.always_cache
@@always_cache
end
|
.always_cache=(value) ⇒ Object
37
38
39
|
# File 'lib/groovy_oneliner.rb', line 37
def self.always_cache=(value)
@@always_cache = value
end
|
.compute(options = {}) ⇒ Object
31
32
33
|
# File 'lib/groovy_oneliner.rb', line 31
def self.compute(options = {})
self.instance.compute(options)
end
|
Instance Method Details
#compute(options = {}) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/groovy_oneliner.rb', line 13
def compute(options = {})
paths = Array(options.fetch(:path))
should_cache = options.fetch(:cache, false) || self.class.always_cache
cache_path = paths.join
if should_cache
cached_content = @cache[cache_path]
return cached_content if cached_content
end
content = paths.reduce([]) { |script, path| script << File.read(path) }.join(';')
output = GroovyOneliner::Converter.new(content).compute
should_cache ? @cache[cache_path] = output : output
end
|