We track folder state as a tree of Node objects.
# File examples/search_cache.rb, line 163 def self.from_json(jnode) path, jcontent = jnode Node.new(path, Node.from_json_content(jcontent)) end
# File examples/search_cache.rb, line 174 def self.from_json_content(jcontent) if jcontent.is_a? Hash map_hash_values(jcontent) { |jchild| Node.from_json jchild } else jcontent end end
# File examples/search_cache.rb, line 150 def initialize(path, content) # The "original" page (i.e. not the lower-case path) @path = path # For files, content is a pair (size, modified) # For folders, content is a hash of children Nodes, keyed by lower-case file names. @content = content end
# File examples/search_cache.rb, line 167 def self.to_json_content(content) if content.is_a? Hash map_hash_values(content) { |child| child.to_json } else content end end
# File examples/search_cache.rb, line 157 def folder?() @content.is_a? Hash end
# File examples/search_cache.rb, line 160 def to_json() [@path, Node.to_json_content(@content)] end