Sha256: f486037925a0ea3a9750be060edeac4c8113e7ed006d5dc8271f34a763dde734

Contents?: true

Size: 981 Bytes

Versions: 7

Compression:

Stored size: 981 Bytes

Contents

require_relative "success_serializer"

module Foobara
  module CommandConnectors
    module Serializers
      class EntitiesToPrimaryKeysSerializer < SuccessSerializer
        def serialize(object)
          case object
          when Entity
            # TODO: handle polymorphism? Would require iterating over the result type not the object!
            # Is there maybe prior art for this in the associations stuff?
            object.primary_key
          when DetachedEntity
            if declaration_data[:detached_to_primary_key]
              object.primary_key
            else
              object.attributes
            end
          when Model
            object.attributes
          when ::Array
            object.map { |element| serialize(element) }
          when ::Hash
            object.to_h do |key, value|
              [serialize(key), serialize(value)]
            end
          else
            object
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foobara-0.0.38 projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb
foobara-0.0.37 projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb
foobara-0.0.36 projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb
foobara-0.0.35 projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb
foobara-0.0.34 projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb
foobara-0.0.33 projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb
foobara-0.0.32 projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb