Class: JMESPath::Runtime Private
- Inherits:
-
Object
- Object
- JMESPath::Runtime
- Defined in:
- lib/jmespath/runtime.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #parser ⇒ Parser readonly private
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Runtime
constructor
private
Constructs a new runtime object for evaluating JMESPath expressions.
- #search(expression, data) ⇒ Mixed? private
Constructor Details
#initialize(options = {}) ⇒ Runtime
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Constructs a new runtime object for evaluating JMESPath expressions.
runtime = JMESPath::Runtime.new
runtime.search(expression, data)
#=> ...
## Caching
When constructing a JMESPath::Runtime, the default parser caches expressions. This significantly speeds up calls to #search multiple times with the same expression but different data. To disable caching, pass ‘:cache_expressions => false` to the constructor or pass a custom `:parser`.
## Optimizing
By default the runtime will perform optimizations on the expression to try to make it run searches as fast as possible. If all your searches use different expressions this might not be worth the extra work, so you can disable the optimizer by passing ‘:optimize_expression => false`. If you disable caching it is also recommended that you disable optimizations, but you don’t have to The optimizer will be disabled if you pass a custom parser with the ‘:parser` option.
59 60 61 |
# File 'lib/jmespath/runtime.rb', line 59 def initialize( = {}) @parser = [:parser] || create_parser() end |
Instance Attribute Details
#parser ⇒ Parser (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 |
# File 'lib/jmespath/runtime.rb', line 64 def parser @parser end |
Instance Method Details
#search(expression, data) ⇒ Mixed?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 |
# File 'lib/jmespath/runtime.rb', line 69 def search(expression, data) @parser.parse(expression).visit(data) end |