Sha256: e4da87103c964bcb50e5f7a9d8c62617e1799ed69c8eec30e38c078a637a6c47

Contents?: true

Size: 938 Bytes

Versions: 8

Compression:

Stored size: 938 Bytes

Contents

module ActiveModel
  class Serializer
    class Association
      class HasMany < Association
        def initialize(name, *args)
          super
          @root_key = @embedded_key.to_s
          @key ||= case CONFIG.default_key_type
            when :name then name.to_s.pluralize
            else "#{name.to_s.singularize}_ids"
          end
        end

        def serializer_class(object, _)
          if use_array_serializer?
            ArraySerializer
          else
            serializer_from_options
          end
        end

        def options
          if use_array_serializer?
            { each_serializer: serializer_from_options }.merge! super
          else
            super
          end
        end

        private

        def use_array_serializer?
          !serializer_from_options ||
            serializer_from_options && !(serializer_from_options <= ArraySerializer)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active_model_serializers-0.9.9 lib/active_model/serializer/association/has_many.rb
active_model_serializers-0.9.8 lib/active_model/serializer/association/has_many.rb
active_model_serializers-0.9.7 lib/active_model/serializer/association/has_many.rb
active_model_serializers-0.9.6 lib/active_model/serializer/association/has_many.rb
active_model_serializers-0.9.5 lib/active_model/serializer/association/has_many.rb
active_model_serializers-0.9.4 lib/active_model/serializer/association/has_many.rb
active_model_serializers-0.9.3 lib/active_model/serializer/association/has_many.rb
active_model_serializers-0.9.1 lib/active_model/serializer/association/has_many.rb