module CanCamel::Cache
Public Class Methods
append(node, path)
click to toggle source
# File lib/can_camel/cache.rb, line 19 def append(node, path) path = [node.name, *path] old = @cache[path] if old old.inherit! node else new = node.dup new.path = path @cache[path] = new children_of(node).each { |child| append child, path } end end
children_of(node)
click to toggle source
# File lib/can_camel/cache.rb, line 11 def children_of(node) return [] unless node cache.select do |path, _value| _, *subpath = path node.path == subpath end.values end
reload!()
click to toggle source
# File lib/can_camel/cache.rb, line 6 def reload! @cache = build_cache inherit_all! end
Private Class Methods
build_cache()
click to toggle source
# File lib/can_camel/cache.rb, line 46 def build_cache Node.all.each_with_object({}) do |node, object| object[node.path] = node end.merge([] => Root.new) end
cache()
click to toggle source
def subpath?(path, subpath)
return if path.empty? return true if subpath.empty? return unless path[-1] == subpath[-1] subpath?(path[0...-1], subpath[0...-1])
end
# File lib/can_camel/cache.rb, line 42 def cache @cache || (reload!; @cache) end
inherit_all!()
click to toggle source
# File lib/can_camel/cache.rb, line 52 def inherit_all! local_cache = cache.dup local_cache.each { |_path, node| node.inherit! } end