Class: TypedEAV::Partition::DefinitionBatch

Inherits:
Object
  • Object
show all
Defined in:
lib/typed_eav/partition/definition_batch.rb

Overview

Internal batched resolver for field definitions visible to many exact partition tuples. It performs one definition SELECT, then applies the same global -> scope -> full-tuple precedence as definitions_by_name independently for every requested tuple.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity_type:, tuples:) ⇒ DefinitionBatch

Returns a new instance of DefinitionBatch.



16
17
18
19
# File 'lib/typed_eav/partition/definition_batch.rb', line 16

def initialize(entity_type:, tuples:)
  @entity_type = entity_type
  @tuples = tuples.uniq
end

Class Method Details

.resolve(entity_type:, tuples:) ⇒ Object



11
12
13
# File 'lib/typed_eav/partition/definition_batch.rb', line 11

def resolve(entity_type:, tuples:)
  new(entity_type: entity_type, tuples: tuples).resolve
end

Instance Method Details

#resolveObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/typed_eav/partition/definition_batch.rb', line 21

def resolve
  tuples.each { |scope, parent_scope| validate_tuple!(scope, parent_scope) }
  return {} if tuples.empty?

  definitions_by_tuple = load_definitions.group_by do |definition|
    [definition.scope, definition.parent_scope]
  end

  tuples.to_h do |tuple|
    visible = candidate_tuples(tuple).flat_map { |candidate| definitions_by_tuple.fetch(candidate, []) }
    [tuple, TypedEAV::Partition.definitions_by_name(visible)]
  end
end