Class: Edoxen::EntityResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/edoxen/entity_resolver.rb

Overview

EntityResolver — resolves Contact/Venue/Body references by walking the three-tier scope hierarchy:

1. Inline: if the entity has no +ref+ and no +local_ref+, return
 it as-is (it carries full data).
2. Document-scoped: if +local_ref+ is set, look up in the
 document-scoped collection (e.g. Meeting#contacts) by matching
 the member's +local_lookup_key+ against +local_ref+.
3. Global register: if +ref+ is set, look up in the global
 register (e.g. ContactRegister) by matching +urn+ against +ref+.

Pure service: no mutation. Returns the resolved entity or nil.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scoped: {}, registers: {}) ⇒ EntityResolver

Returns a new instance of EntityResolver.



19
20
21
22
# File 'lib/edoxen/entity_resolver.rb', line 19

def initialize(scoped: {}, registers: {})
  @scoped_collections = scoped
  @global_registers = registers
end

Instance Attribute Details

#global_registersObject (readonly)

Returns the value of attribute global_registers.



17
18
19
# File 'lib/edoxen/entity_resolver.rb', line 17

def global_registers
  @global_registers
end

#scoped_collectionsObject (readonly)

Returns the value of attribute scoped_collections.



17
18
19
# File 'lib/edoxen/entity_resolver.rb', line 17

def scoped_collections
  @scoped_collections
end

Instance Method Details

#resolve(entity) ⇒ Object



24
25
26
27
28
# File 'lib/edoxen/entity_resolver.rb', line 24

def resolve(entity)
  return entity unless entity.reference?

  resolve_local(entity) || resolve_global(entity)
end

#resolve_all(entities) ⇒ Object



30
31
32
# File 'lib/edoxen/entity_resolver.rb', line 30

def resolve_all(entities)
  entities.map { |e| resolve(e) }
end