class Prelude::Preloader
Public Class Methods
new(klass, records)
click to toggle source
# File lib/prelude/preloader.rb, line 3 def initialize(klass, records) @klass = klass @records = records end
Public Instance Methods
fetch(name, *args)
click to toggle source
# File lib/prelude/preloader.rb, line 8 def fetch(name, *args) method = @klass.prelude_methods.fetch(name) # Load and set the results for each record results = preload(method, args) @records.each do |record| record.set_preloaded_value_for(name, args, results[record]) end results end
Private Instance Methods
preload(method, args)
click to toggle source
Preload the given field with the given args for all records
# File lib/prelude/preloader.rb, line 23 def preload(method, args) method.call(@records, *args) end