Class: Coradoc::Reference::Catalog::Composite
- Inherits:
-
Object
- Object
- Coradoc::Reference::Catalog::Composite
- Includes:
- Protocol
- Defined in:
- lib/coradoc/reference/catalog/composite.rb
Overview
Composes multiple catalogs. Lookup asks EVERY child and merges
the hits: exactly one hit returns the Content; several hits
return an Array (which the Resolver surfaces per the
ambiguous: policy). Precedence between catalogs is a
resolver/policy concern, not a lookup concern:
Composite.new(
Local.from_doc(doc),
Collection.from_manifest(...),
Remote.new(client: http_client)
)
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
Instance Method Summary collapse
- #ambiguous?(address) ⇒ Boolean
- #each_pair(&block) ⇒ Object
-
#initialize(*children) ⇒ Composite
constructor
A new instance of Composite.
- #lookup(address) ⇒ Object
- #recognizes_scheme?(scheme) ⇒ Boolean
Constructor Details
#initialize(*children) ⇒ Composite
Returns a new instance of Composite.
22 23 24 |
# File 'lib/coradoc/reference/catalog/composite.rb', line 22 def initialize(*children) @children = children.flatten end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
20 21 22 |
# File 'lib/coradoc/reference/catalog/composite.rb', line 20 def children @children end |
Instance Method Details
#ambiguous?(address) ⇒ Boolean
40 41 42 43 |
# File 'lib/coradoc/reference/catalog/composite.rb', line 40 def ambiguous?(address) result = lookup(address) result.is_a?(Array) && result.size > 1 end |
#each_pair(&block) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/coradoc/reference/catalog/composite.rb', line 45 def each_pair(&block) return to_enum(:each_pair) unless block_given? children.each do |catalog| catalog.each_pair(&block) end end |
#lookup(address) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/coradoc/reference/catalog/composite.rb', line 26 def lookup(address) results = [] children.each do |catalog| result = catalog.lookup(address) next if result.nil? results.concat(Array(result)) end return nil if results.empty? return results.first if results.size == 1 results end |
#recognizes_scheme?(scheme) ⇒ Boolean
53 54 55 |
# File 'lib/coradoc/reference/catalog/composite.rb', line 53 def recognizes_scheme?(scheme) children.any? { |catalog| catalog.recognizes_scheme?(scheme) } end |