Class: Serega::AttributeValueResolvers::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/attribute_value_resolvers/batch.rb

Overview

Builds value resolver class for attributes with :batch option

Instance Method Summary collapse

Constructor Details

#initialize(loader_name, id_method) ⇒ Batch

Returns a new instance of Batch.



55
56
57
58
# File 'lib/serega/attribute_value_resolvers/batch.rb', line 55

def initialize(loader_name, id_method)
  @loader_name = loader_name
  @id_method = id_method
end

Instance Method Details

#call(obj, batches:) ⇒ Object

Finds object attribute value from hash of batch_loaded values



61
62
63
# File 'lib/serega/attribute_value_resolvers/batch.rb', line 61

def call(obj, batches:)
  batches.fetch(@loader_name)[obj.public_send(@id_method)]
end