Class: Logasm::Preprocessors::JSONPointerTrie
- Inherits:
-
Object
- Object
- Logasm::Preprocessors::JSONPointerTrie
- Defined in:
- lib/logasm/preprocessors/json_pointer_trie.rb
Constant Summary collapse
- SEPARATOR =
'/'.freeze
- WILDCARD =
'~'.freeze
- 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
Returns a new instance of JSONPointerTrie.
10 11 12 13 |
# File 'lib/logasm/preprocessors/json_pointer_trie.rb', line 10 def initialize(cache_size: DEFAULT_CACHE_SIZE, **) @root_node = {} @cache = LruRedux::Cache.new(cache_size) end |
Instance Method Details
#include?(path) ⇒ Boolean
23 24 25 |
# File 'lib/logasm/preprocessors/json_pointer_trie.rb', line 23 def include?(path) @cache.getset(path) { traverse_path(path) } end |
#insert(pointer) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/logasm/preprocessors/json_pointer_trie.rb', line 15 def insert(pointer) split_path(pointer).reduce(@root_node) do |tree, key| tree[key] ||= {} end self end |