class Logasm::Preprocessors::JSONPointerTrie
Constants
- DEFAULT_CACHE_SIZE
- SEPARATOR
- WILDCARD
Public Class Methods
new(cache_size: DEFAULT_CACHE_SIZE, **)
click to toggle source
# 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
Public Instance Methods
include?(path)
click to toggle source
# File lib/logasm/preprocessors/json_pointer_trie.rb, line 23 def include?(path) @cache.getset(path) { traverse_path(path) } end
insert(pointer)
click to toggle source
# 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
Private Instance Methods
split_path(path)
click to toggle source
# File lib/logasm/preprocessors/json_pointer_trie.rb, line 35 def split_path(path) path.split(SEPARATOR).reject(&:empty?) end
traverse_path(path)
click to toggle source
# File lib/logasm/preprocessors/json_pointer_trie.rb, line 29 def traverse_path(path) split_path(path).reduce(@root_node) do |node, key| node[key] || node[WILDCARD] || (break false) end end