class JMESPath::DEFAULT_PARSER

Public Class Methods

new(options = {}) click to toggle source
# File lib/jmespath/caching_parser.rb, line 6
def initialize(options = {})
  @parser = options[:parser] || Parser.new(options)
  @mutex = Mutex.new
  @cache = {}
end

Public Instance Methods

parse(expression) click to toggle source
# File lib/jmespath/caching_parser.rb, line 12
def parse(expression)
  if cached = @cache[expression]
    cached
  else
    cache_expression(expression)
  end
end

Private Instance Methods

cache_expression(expression) click to toggle source
# File lib/jmespath/caching_parser.rb, line 22
def cache_expression(expression)
  @mutex.synchronize do
    @cache.clear if @cache.size > 1000
    @cache[expression] = @parser.parse(expression)
  end
end