Module: Protector::Adapters::ActiveRecord::SingularAssociation

Extended by:
ActiveSupport::Concern
Defined in:
lib/protector/adapters/active_record/singular_association.rb

Overview

Patches ActiveRecord::Associations::SingularAssociation

Instance Method Summary collapse

Instance Method Details

#build_record_with_protector(*args) ⇒ Object

Forwards protection subject to the new instance



20
21
22
23
# File 'lib/protector/adapters/active_record/singular_association.rb', line 20

def build_record_with_protector(*args)
  return build_record_without_protector(*args) unless protector_subject?
  build_record_without_protector(*args).restrict!(protector_subject)
end

#reader_with_protector(*args) ⇒ Object

Reader has to be explicitly overrided for cases when the loaded association is cached



14
15
16
17
# File 'lib/protector/adapters/active_record/singular_association.rb', line 14

def reader_with_protector(*args)
  return reader_without_protector(*args) unless protector_subject?
  reader_without_protector(*args).try :restrict!, protector_subject
end