Class: Coradoc::Reference::Resolver::Catalog

Inherits:
Resolver::Base
  • Object
show all
Defined in:
lib/coradoc/reference/resolver/catalog.rb

Overview

Asks one catalog. Applies the ambiguous: policy in-line. Does NOT apply the missing: policy — that's the caller's call (Resolution orchestrator) — but it does surface the Missing Result so the caller can decide.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(catalog:, ambiguous: :disambiguate, missing: :warn) ⇒ Catalog

Returns a new instance of Catalog.



13
14
15
16
17
18
# File 'lib/coradoc/reference/resolver/catalog.rb', line 13

def initialize(catalog:, ambiguous: :disambiguate, missing: :warn)
  super()
  @catalog = catalog
  @ambiguous_policy = ambiguous
  @missing_policy = missing
end

Instance Attribute Details

#ambiguous_policyObject (readonly)

Returns the value of attribute ambiguous_policy.



11
12
13
# File 'lib/coradoc/reference/resolver/catalog.rb', line 11

def ambiguous_policy
  @ambiguous_policy
end

#catalogObject (readonly)

Returns the value of attribute catalog.



11
12
13
# File 'lib/coradoc/reference/resolver/catalog.rb', line 11

def catalog
  @catalog
end

#missing_policyObject (readonly)

Returns the value of attribute missing_policy.



11
12
13
# File 'lib/coradoc/reference/resolver/catalog.rb', line 11

def missing_policy
  @missing_policy
end

Instance Method Details

#resolve(edge) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/coradoc/reference/resolver/catalog.rb', line 20

def resolve(edge)
  address = edge.address
  return missing_for(edge, address) unless catalog.recognizes_scheme?(address.scheme)

  result = catalog.lookup(address)
  return missing_for(edge, address) if result.nil?

  return resolved_for(edge, address, result) unless result.is_a?(Array)

  resolve_ambiguous(edge, address, result)
end