Sha256: 9e6eaeb4577ac621346be6d9fb0b4719c0365efe37f142ed80b7a9341db2aa34

Contents?: true

Size: 618 Bytes

Versions: 25

Compression:

Stored size: 618 Bytes

Contents

module Moneta
  module Api
    class KeyValueSerializer
      class << self
        def serialize(entity)
          attributes = entity.properties

          attributes.collect do |property, _|
            value = entity.public_send(property)
            key = property.to_s.swapcase

            { 'key' => key, 'value' => value } unless value.nil?
          end.compact
        end

        def deserialize(attributes)
          attributes.each_with_object({}) do |attribute, hash|
            hash[attribute[:key].to_sym] = attribute.tap { |a| a.delete(:key) }
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
moneta-api-1.5.0 lib/moneta/api/key_value_serializer.rb
moneta-api-1.4.0 lib/moneta/api/key_value_serializer.rb
moneta-api-1.3.0 lib/moneta/api/key_value_serializer.rb
moneta-api-1.2.1 lib/moneta/api/key_value_serializer.rb
moneta-api-1.2.0 lib/moneta/api/key_value_serializer.rb