Sha256: d11a37ee139b5a2094e0078593f55a84bac9e8d0c72a664193de630e1634ac73

Contents?: true

Size: 929 Bytes

Versions: 27

Compression:

Stored size: 929 Bytes

Contents

module Foobara
  module CommandConnectors
    module Serializers
      class AggregateSerializer < 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?
            unless object.loaded?
              # :nocov:
              raise "#{object} is not loaded so cannot serialize it"
              # :nocov:
            end

            transform(object.attributes)
          when Model
            transform(object.attributes)
          when Array
            object.map { |element| transform(element) }
          when Hash
            object.to_h do |key, value|
              [transform(key), transform(value)]
            end
          else
            object
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
foobara-0.0.7 projects/command_connectors/src/serializers/aggregate_serializer.rb
foobara-0.0.6 projects/command_connectors/src/serializers/aggregate_serializer.rb
foobara-0.0.5 projects/command_connectors/src/serializers/aggregate_serializer.rb
foobara-0.0.4 projects/command_connectors/src/serializers/aggregate_serializer.rb
foobara-0.0.3 projects/command_connectors/src/serializers/aggregate_serializer.rb
foobara-0.0.2 projects/command_connectors/src/serializers/aggregate_serializer.rb
foobara-0.0.1 projects/command_connectors/src/serializers/aggregate_serializer.rb