Sha256: f1ba87273368a87dff904b57ba752da9d831d6464661b72ddef380e4e3076b6b
Contents?: true
Size: 893 Bytes
Versions: 5
Compression:
Stored size: 893 Bytes
Contents
module Protector module Adapters module ActiveRecord # Patches `ActiveRecord::Associations::SingularAssociation` module SingularAssociation extend ActiveSupport::Concern included do alias_method_chain :reader, :protector end # Reader has to be explicitly overrided for cases when the # loaded association is cached def reader_with_protector(*args) return reader_without_protector(*args) unless protector_subject? reader_without_protector(*args).try :restrict!, protector_subject end # Forwards protection subject to the new instance def build_record_with_protector(*args) return build_record_without_protector(*args) unless protector_subject? build_record_without_protector(*args).restrict!(protector_subject) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems