Class: Lifesaver::Notification::EagerLoader
- Inherits:
-
Object
- Object
- Lifesaver::Notification::EagerLoader
- Defined in:
- lib/lifesaver/notification/eager_loader.rb
Instance Method Summary collapse
- #add_model(class_name, id) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ EagerLoader
constructor
A new instance of EagerLoader.
- #load ⇒ Object
Constructor Details
#initialize ⇒ EagerLoader
Returns a new instance of EagerLoader.
4 5 6 7 |
# File 'lib/lifesaver/notification/eager_loader.rb', line 4 def initialize @models_to_load = {} @loaded_models = {} end |
Instance Method Details
#add_model(class_name, id) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/lifesaver/notification/eager_loader.rb', line 9 def add_model(class_name, id) return if model_previously_added?(class_name, id) models_to_load[class_name] ||= [] models_to_load[class_name] << id mark_model_added(class_name, id) end |
#empty? ⇒ Boolean
26 27 28 |
# File 'lib/lifesaver/notification/eager_loader.rb', line 26 def empty? @models_to_load.empty? end |
#load ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/lifesaver/notification/eager_loader.rb', line 16 def load models = [] models_to_load.each do |class_name, ids| klass = class_name.classify.constantize models |= load_associations(klass, ids) models_to_load.delete(class_name) end models end |