Class: CacheQL::RecordLoader
- Inherits:
-
GraphQL::Batch::Loader
- Object
- GraphQL::Batch::Loader
- CacheQL::RecordLoader
- Defined in:
- lib/cacheql/record_loader.rb
Instance Method Summary collapse
-
#initialize(model, column: model.primary_key, where: nil) ⇒ RecordLoader
constructor
A new instance of RecordLoader.
- #load(key) ⇒ Object
- #perform(keys) ⇒ Object
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 |