Module: Samvera::NestingIndexer

Defined in:
lib/samvera/nesting_indexer.rb,
lib/samvera/nesting_indexer/railtie.rb,
lib/samvera/nesting_indexer/version.rb,
lib/samvera/nesting_indexer/adapters.rb,
lib/samvera/nesting_indexer/documents.rb,
lib/samvera/nesting_indexer/exceptions.rb,
lib/samvera/nesting_indexer/configuration.rb,
lib/samvera/nesting_indexer/repository_reindexer.rb,
lib/samvera/nesting_indexer/relationship_reindexer.rb,
lib/samvera/nesting_indexer/adapters/abstract_adapter.rb,
lib/samvera/nesting_indexer/adapters/in_memory_adapter.rb

Overview

Establishing namespace

Defined Under Namespace

Modules: Adapters, Documents, Exceptions Classes: Railtie

Constant Summary collapse

VERSION =
"1.0.0".freeze

Class Method Summary collapse

Class Method Details

.adapterObject

Exposes the data adapter to use for the reindexing process.

Returns:

  • Object that implementes the Samvera::NestingIndexer::Adapters::AbstractAdapter method interface

See Also:



64
65
66
# File 'lib/samvera/nesting_indexer.rb', line 64

def self.adapter
  configuration.adapter
end

.configurationObject Also known as: config

Contains the Samvera::NestingIndexer configuration information that is referenceable from wit

See Also:

  • Configuration


50
51
52
# File 'lib/samvera/nesting_indexer.rb', line 50

def self.configuration
  @configuration ||= Configuration.new
end

.configure(&block) ⇒ Object

Capture the configuration information

See Also:



75
76
77
78
79
80
81
# File 'lib/samvera/nesting_indexer.rb', line 75

def self.configure(&block)
  @configuration_block = block
  # The Rails load sequence means that some of the configured Targets may
  # not be loaded; As such I am not calling configure! instead relying on
  # Samvera::NestingIndexer::Railtie to handle the configure! call
  configure! unless defined?(Rails)
end

.configure!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



84
85
86
87
88
# File 'lib/samvera/nesting_indexer.rb', line 84

def self.configure!
  return false unless @configuration_block.respond_to?(:call)
  @configuration_block.call(configuration)
  @configuration_block = nil
end

.reindex_all!(maximum_nesting_depth: configuration.maximum_nesting_depth) ⇒ Boolean

Responsible for reindexing the entire preservation layer.

Parameters:

  • maximum_nesting_depth (Integer) (defaults to: configuration.maximum_nesting_depth)
    • there to guard against cyclic graphs

Returns:

  • (Boolean)
    • It was successful

Raises:

  • Samvera::Exceptions::ReindexingError - There was a problem reindexing the graph.



38
39
40
41
42
43
44
# File 'lib/samvera/nesting_indexer.rb', line 38

def self.reindex_all!(maximum_nesting_depth: configuration.maximum_nesting_depth)
  # While the RepositoryReindexer is responsible for reindexing everything, I
  # want to inject the lambda that will reindex a single item.
  id_reindexer = method(:reindex_relationships)
  RepositoryReindexer.call(maximum_nesting_depth: maximum_nesting_depth, id_reindexer: id_reindexer, configuration: configuration)
  true
end

.reindex_relationships(id:, maximum_nesting_depth: configuration.maximum_nesting_depth) ⇒ Boolean Also known as: reindex

Responsible for reindexing the associated document for the given :id and the descendants of that :id. In a perfect world we could reindex the id as well; But that is for another test.

Parameters:

  • id (String)
    • The permanent identifier of the object that will be reindexed along with its children.

  • maximum_nesting_depth (Integer) (defaults to: configuration.maximum_nesting_depth)
    • used to short-circuit overly deep nesting as well as prevent accidental cyclic graphs

    from creating an infinite loop.

Returns:

  • (Boolean)
    • It was successful

Raises:

  • Samvera::Exceptions::CycleDetectionError - A possible cycle was detected

  • Samvera::Exceptions::ExceededMaximumNestingDepthError - We exceeded our maximum depth

  • Samvera::Exceptions::DocumentIsItsOwnAncestorError - A document we were about to index appeared to be its own ancestor



22
23
24
25
# File 'lib/samvera/nesting_indexer.rb', line 22

def self.reindex_relationships(id:, maximum_nesting_depth: configuration.maximum_nesting_depth)
  RelationshipReindexer.call(id: id, maximum_nesting_depth: maximum_nesting_depth, configuration: configuration)
  true
end