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.



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

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



68
69
70
# File 'lib/serega/attribute_value_resolvers/batch.rb', line 68

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