Sha256: af41cdfc4a5e4905f1d994c384c4b8641bc58c88daa1b9a7bb2131b87b23dafa

Contents?: true

Size: 933 Bytes

Versions: 1

Compression:

Stored size: 933 Bytes

Contents

require_relative "success_serializer"

module Foobara
  module CommandConnectors
    module Serializers
      class EntitiesToPrimaryKeysSerializer < SuccessSerializer
        def serialize(object)
          case object
          # What of DetachedEntity? I guess we should treat it as a model since we can't cast from primary key value to
          # a record?
          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 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

1 entries across 1 versions & 1 rubygems

Version Path
foobara-0.0.31 projects/command_connectors/src/serializers/entities_to_primary_keys_serializer.rb