Sha256: c93be0c908b74577e0bd3fe0ef9036a5c1cc741ae8ab3fd8802c3f61472119c9

Contents?: true

Size: 848 Bytes

Versions: 18

Compression:

Stored size: 848 Bytes

Contents

module Protector
  module Adapters
    module ActiveRecord
      # Patches `ActiveRecord::Associations::SingularAssociation` and `ActiveRecord::Associations::CollectionAssociation`
      module Association
        extend ActiveSupport::Concern

        included do
          # AR 4 has renamed `scoped` to `scope`
          if method_defined?(:scope)
            alias_method_chain :scope, :protector
          else
            alias_method "scope_without_protector", "scoped"
            alias_method "scoped", "scope_with_protector"
          end
        end

        # Wraps every association with current subject
        def scope_with_protector(*args)
          scope = scope_without_protector(*args)
          scope = scope.restrict!(owner.protector_subject) if owner.protector_subject?
          scope
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
protector-0.6.4 lib/protector/adapters/active_record/association.rb
protector-0.6.3 lib/protector/adapters/active_record/association.rb
protector-0.6.2 lib/protector/adapters/active_record/association.rb
protector-0.6.1 lib/protector/adapters/active_record/association.rb
protector-0.6.0 lib/protector/adapters/active_record/association.rb
protector-0.6.0.beta.1 lib/protector/adapters/active_record/association.rb
protector-0.5.5 lib/protector/adapters/active_record/association.rb
protector-0.5.4 lib/protector/adapters/active_record/association.rb
protector-0.5.3 lib/protector/adapters/active_record/association.rb
protector-0.5.2 lib/protector/adapters/active_record/association.rb
protector-0.5.1 lib/protector/adapters/active_record/association.rb
protector-0.4.1 lib/protector/adapters/active_record/association.rb
protector-0.4.0 lib/protector/adapters/active_record/association.rb
protector-0.3.3 lib/protector/adapters/active_record/association.rb
protector-0.3.2 lib/protector/adapters/active_record/association.rb
protector-0.3.1 lib/protector/adapters/active_record/association.rb
protector-0.3.0 lib/protector/adapters/active_record/association.rb
protector-0.3.0.beta.2 lib/protector/adapters/active_record/association.rb