Class: CacheQL::RecordLoader

Inherits:
GraphQL::Batch::Loader
  • Object
show all
Defined in:
lib/cacheql/record_loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, column: model.primary_key, where: nil) ⇒ RecordLoader

Returns a new instance of RecordLoader.



5
6
7
8
9
10
# File 'lib/cacheql/record_loader.rb', line 5

def initialize(model, column: model.primary_key, where: nil)
  @model = model
  @column = column.to_s
  @column_type = model.type_for_attribute(@column)
  @where = where
end

Instance Method Details

#load(key) ⇒ Object



12
13
14
# File 'lib/cacheql/record_loader.rb', line 12

def load(key)
  super(@column_type.cast(key))
end

#perform(keys) ⇒ Object



16
17
18
19
# File 'lib/cacheql/record_loader.rb', line 16

def perform(keys)
  query(keys).each { |record| fulfill(record.public_send(@column), record) }
  keys.each { |key| fulfill(key, nil) unless fulfilled?(key) }
end