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

Instance Method Details

#protector_subjectObject

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

Returns:

  • (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
# File 'lib/protector/adapters/active_record/preloader.rb', line 31

def scope_with_protector(*args)
  return scope_without_protector unless protector_subject?

  @meta ||= klass.protector_meta.evaluate(protector_subject)

  scope_without_protector.merge(@meta.relation)
end