Sha256: e06740a658d9750e9ccea80e779881ad6d639f00ef4e18a8d09e40539d98f72c

Contents?: true

Size: 998 Bytes

Versions: 1

Compression:

Stored size: 998 Bytes

Contents

module Protector
  module CanCan
    module Resource extend ActiveSupport::Concern
      included do
        alias_method_chain :load_resource, :protector
        alias_method_chain :load_collection, :protector
      end

      def load_resource_with_protector(*args)
        resource = load_resource_without_protector(*args)

        if resource.respond_to?(:restrict!) \
            && !resource.protector_subject? \
            && current_ability.protector_subject?

          resource = resource.restrict!(current_ability.protector_subject)
        end
        
        resource
      end

      def load_collection_with_protector(*args)
        collection = load_collection_without_protector(*args)

        if collection.respond_to?(:restrict!) \
            && !collection.protector_subject? \
            && current_ability.protector_subject?

          collection = collection.restrict!(current_ability.protector_subject)
        end
        
        collection
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
protector-cancan-0.1.0 lib/protector/cancan/resource.rb