module Scrivito module Backend # Abstract Base for Index Implementations module Index IMPLEMENTATIONS = [ Backend::PathIndex, Backend::ParentPathIndex, Backend::PermalinkIndex, ].freeze IMPLEMENTATION_BY_NAME = IMPLEMENTATIONS.inject({}) do |result, index| result.merge(index.id => index) end def self.by_name(name) IMPLEMENTATION_BY_NAME[name.to_s] or raise Scrivito::InternalError, "unknown index #{name}" end def id abstract_base_method end def update(key, cached_result, change_index) updated = Set.new(cached_result) change_index.each do |id, data| value = extract_update_value_from_data(data) if value == key updated.add(id) else updated.delete(id) end end updated.to_a end def extract_update_value_from_data(data) abstract_base_method end def group_by(keys, obj_datas) return [obj_datas] if keys.length == 1 group_by_multiple(keys, obj_datas) end def group_by_multiple(parent_paths, obj_datas) abstract_base_method end private def abstract_base_method raise Scrivito::InternalError, "not implemented" end end end end