Sha256: 926c6f6b0bf993540a231d8ce0d7e44705fba084cd3e39f44e046b3865446ec3

Contents?: true

Size: 806 Bytes

Versions: 1

Compression:

Stored size: 806 Bytes

Contents

module ActiveModel
  class Serializer
    module Associations #:nodoc:
      class Config #:nodoc:

        def authorize?
          !!option(:authorize)
        end

      end

      class HasMany #:nodoc:

        def serialize_with_cancan
          return serialize_without_cancan unless authorize?
          associated_object.select{|o| source_serializer.can?(:read, o)}.map do |item|
            find_serializable(item).serializable_hash
          end
        end
        alias_method_chain :serialize, :cancan

      end

      class HasOne #:nodoc:

        def serialize_with_cancan
          return nil unless !authorize? || source_serializer.can?(:read, associated_object)
          serialize_without_cancan
        end
        alias_method_chain :serialize, :cancan

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_model_serializers-cancan-0.0.2 lib/active_model_serializers/cancan/associations.rb