Module: Protector::Adapters::ActiveRecord::Preloader::Association
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/protector/adapters/active_record/preloader.rb
Overview
Patches ActiveRecord::Associations::Preloader::Association
Instance Method Summary collapse
-
#protector_subject ⇒ Object
Gets current subject of preloading association.
- #protector_subject? ⇒ Boolean
-
#scope_with_protector(*args) ⇒ Object
Restricts preloading association scope with subject of the owner.
Instance Method Details
#protector_subject ⇒ Object
Gets current subject of preloading association
20 21 22 23 24 |
# File 'lib/protector/adapters/active_record/preloader.rb', line 20 def protector_subject # Owners are always loaded from the single source # having same protector_subject owners.first.protector_subject end |
#protector_subject? ⇒ Boolean
26 27 28 |
# File 'lib/protector/adapters/active_record/preloader.rb', line 26 def protector_subject? owners.first.protector_subject? end |
#scope_with_protector(*args) ⇒ Object
Restricts preloading association scope with subject of the owner
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/protector/adapters/active_record/preloader.rb', line 31 def scope_with_protector(*args) return scope_without_protector unless protector_subject? @meta ||= klass..evaluate( Protector::Adapters::ActiveRecord, klass, protector_subject ) scope_without_protector.merge(@meta.relation) end |