class GroovyOneliner

Constants

VERSION

Public Class Methods

always_cache() click to toggle source
# File lib/groovy_oneliner.rb, line 41
def self.always_cache
  @@always_cache
end
always_cache=(value) click to toggle source
# File lib/groovy_oneliner.rb, line 37
def self.always_cache=(value)
  @@always_cache = value
end
compute(options = {}) click to toggle source
# File lib/groovy_oneliner.rb, line 31
def self.compute(options = {})
  self.instance.compute(options)
end
new() click to toggle source
# File lib/groovy_oneliner.rb, line 9
def initialize
  @cache = GroovyOneliner::Cache.new
end

Public Instance Methods

compute(options = {}) click to toggle source
# 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