Sha256: 3fdcc1dd7c65075e03380ce462bbb8d8f87ca2fa66fa8b40affb107a9a3ae523

Contents?: true

Size: 696 Bytes

Versions: 1

Compression:

Stored size: 696 Bytes

Contents

require 'active_model/serializer/reflection'

module ActiveModel
  class Serializer
    class Reflection < Field
      def authorize?
        !!options[:authorize]
      end

      def value_with_cancan(serializer, include_slice)
        val = value_without_cancan(serializer, include_slice)
        unless authorize?
          return val
        end
        if val.kind_of?(Array)
          val.select do |item|
            serializer.current_ability.can?(:read, item)
          end
        else
          if serializer.current_ability.can?(:read, val)
            val
          else
            nil
          end
        end
      end
      alias_method_chain :value, :cancan
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_model_serializers_cancancan-0.2.0 lib/active_model_serializers/cancan/associations.rb