Module: URIResolver

Defined in:
backend/app/lib/uri_resolver.rb

Overview

Resolving is the process of taking one or more records with embedded URI links (refs) and inlining the JSON of those linked records.

For example, if we have:

=> “Some Archival Object”, ‘resource’ => {‘ref’ => ‘/repositories/2/resources/123’}

Then resolving this document on “resource” would return:

{ ‘title’ => “Some Archival Object”, ‘resource’ => { ‘ref’ => ‘/repositories/2/resources/123’, ‘_resolved’ => { ‘title’ => “Some Resource Record”, … } } }

You can resolve more than one record at once and more than one ref type at once. You can also resolve a ref within a resolved record by creating a path of refs with double colons, like “resource::linked_agent”.

Defined Under Namespace

Classes: ASModelResolver, ResolverType, TreeResolver, URIResolverImplementation

Class Method Summary collapse

Class Method Details

.add_resolve_wrapper(wrapper) ⇒ Object



29
30
31
32
# File 'backend/app/lib/uri_resolver.rb', line 29

def self.add_resolve_wrapper(wrapper)
  @resolve_wrappers ||= []
  @resolve_wrappers << wrapper
end

.ensure_reference_is_valid(reference, active_repository = nil) ⇒ Object



72
73
74
# File 'backend/app/lib/uri_resolver.rb', line 72

def self.ensure_reference_is_valid(reference, active_repository = nil)
  URIResolverImplementation.new([]).ensure_reference_is_valid(reference, active_repository)
end

.register_resolver(resolver) ⇒ Object

Allow API consumers (such as plugins) to hook into the resolving process



68
69
70
# File 'backend/app/lib/uri_resolver.rb', line 68

def self.register_resolver(resolver)
  URIResolverImplementation.register_resolver(resolver)
end

.resolve_references(records, properties_to_resolve, ignored = nil) ⇒ Object

Additional ignored argugment to account for callers using the old API which required an env. In the long-run, we can get rid of this.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'backend/app/lib/uri_resolver.rb', line 40

def resolve_references(records, properties_to_resolve, ignored = nil)
  if ignored
    msg = ('Three-argment call to resolve_references is deprecated.' +
           'The "env" parameter is no longer needed.')

    if ASpaceEnvironment.environment == :unit_test
      raise msg
    else
      Log.warn(msg)
    end
  end

  result = if properties_to_resolve
             URIResolverImplementation.new(properties_to_resolve).resolve_references(records)
           else
             records
           end

  URIResolver.resolve_wrappers.each do |resolve_wrapper|
    result = resolve_wrapper.resolve(result, records, properties_to_resolve)
  end

  result
end

.resolve_wrappersObject



34
35
36
# File 'backend/app/lib/uri_resolver.rb', line 34

def self.resolve_wrappers
  @resolve_wrappers ||= []
end