module Enumpath
A JSONPath-compatible library for navigating Ruby objects using path expressions
TODO: Investigate supporting anchored paths (`$.foo.bar…`, `@.foo.bar…`)
TODO: Consider adding support for other return types?
- dig compatible array with typecast keys - dot-notation style path for Enumpath
Constants
- VERSION
Attributes
Whether verbose mode is enabled. When enabled, the {Enumpath::Logger} will print information to the logging stream to assist in debugging path expressions. Defaults to false
@return [true,false]
Public Class Methods
Resolve a path expression against an enumerable
@param path (see Enumpath::Path#initialize) @param enum (see Enumpath::Path#apply
) @param options [optional, Hash] @option options [Symbol] :result_type (:value) The type of results to return, `:value` or `:path` @option options [true, false] :verbose (false) Whether to enable additional output for debugging @return (see Enumpath::Path#apply
)
# File lib/enumpath.rb, line 32 def apply(path, enum, options = {}) logger.level = 0 @verbose = options.delete(:verbose) || false Enumpath::Path.new(path, result_type: options.delete(:result_type)).apply(enum) end
A shortcut to {Enumpath::logger.log}
@private @see Enumpath::Logger#log
# File lib/enumpath.rb, line 50 def log(title) block_given? ? logger.log(title, &-> { yield }) : logger.log(title) end
The {Enumpath::Logger} instance to use with verbose mode
@private @return [Enumpath::Logger]
# File lib/enumpath.rb, line 42 def logger @logger ||= Enumpath::Logger.new end
A lightweight in-memory cache for caching normalized path expressions
@private @return [MiniCache::Store]
# File lib/enumpath.rb, line 58 def path_cache @path_cache ||= MiniCache::Store.new end