Class: Logasm::Preprocessors::JSONPointerTrie

Inherits:
Object
  • Object
show all
Defined in:
lib/logasm/preprocessors/json_pointer_trie.rb

Constant Summary collapse

SEPARATOR =
'/'.freeze
WILDCARD =
'~'.freeze
DEFAULT_CACHE_SIZE =
100

Instance Method Summary collapse

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

Returns:

  • (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