Class: Lenjador::Preprocessors::JSONPointerTrie
- Inherits:
-
Object
- Object
- Lenjador::Preprocessors::JSONPointerTrie
- Defined in:
- lib/lenjador/preprocessors/json_pointer_trie.rb
Constant Summary collapse
- SEPARATOR =
'/'- WILDCARD =
'~'- DEFAULT_CACHE_SIZE =
100
Instance Method Summary collapse
- #include?(path) ⇒ Boolean
-
#initialize(cache_size: DEFAULT_CACHE_SIZE) ⇒ JSONPointerTrie
constructor
A new instance of JSONPointerTrie.
- #insert(pointer) ⇒ Object
Constructor Details
#initialize(cache_size: DEFAULT_CACHE_SIZE) ⇒ JSONPointerTrie
12 13 14 15 |
# File 'lib/lenjador/preprocessors/json_pointer_trie.rb', line 12 def initialize(cache_size: DEFAULT_CACHE_SIZE, **) @root_node = {} @cache = LruRedux::Cache.new(cache_size) end |
Instance Method Details
#include?(path) ⇒ Boolean
25 26 27 |
# File 'lib/lenjador/preprocessors/json_pointer_trie.rb', line 25 def include?(path) @cache.getset(path) { traverse_path(path) } end |
#insert(pointer) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/lenjador/preprocessors/json_pointer_trie.rb', line 17 def insert(pointer) split_path(pointer).reduce(@root_node) do |tree, key| tree[key] ||= {} end self end |