Class: ActiveRecordCustomPreloader::Preloader
- Inherits:
-
Object
- Object
- ActiveRecordCustomPreloader::Preloader
- Defined in:
- lib/active_record_custom_preloader/preloader.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(klass, name, args) ⇒ Preloader
constructor
A new instance of Preloader.
-
#preload(records) ⇒ Object
override this method in a subclass to provide customized preloading behavior.
Constructor Details
#initialize(klass, name, args) ⇒ Preloader
Returns a new instance of Preloader.
7 8 9 10 11 |
# File 'lib/active_record_custom_preloader/preloader.rb', line 7 def initialize(klass, name, args) @klass = klass @name = name @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
5 6 7 |
# File 'lib/active_record_custom_preloader/preloader.rb', line 5 def args @args end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/active_record_custom_preloader/preloader.rb', line 5 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/active_record_custom_preloader/preloader.rb', line 5 def name @name end |
Instance Method Details
#preload(records) ⇒ Object
override this method in a subclass to provide customized preloading behavior
14 15 16 17 18 19 20 |
# File 'lib/active_record_custom_preloader/preloader.rb', line 14 def preload(records) values = args.fetch(:values).call(records) records.each do |record| value = values[record.id] record._set_custom_preloaded_value(name, value) end end |