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-2.1.0 lib/moneta/api/key_value_serializer.rb
moneta-api-2.0.0 lib/moneta/api/key_value_serializer.rb
moneta-api-2.0.0.rc2 lib/moneta/api/key_value_serializer.rb
moneta-api-2.0.0.rc1 lib/moneta/api/key_value_serializer.rb
moneta-api-1.13.0 lib/moneta/api/key_value_serializer.rb
moneta-api-1.12.8 lib/moneta/api/key_value_serializer.rb
moneta-api-1.12.7 lib/moneta/api/key_value_serializer.rb
moneta-api-1.12.6 lib/moneta/api/key_value_serializer.rb
moneta-api-1.12.5 lib/moneta/api/key_value_serializer.rb
moneta-api-1.12.4 lib/moneta/api/key_value_serializer.rb
moneta-api-1.12.3 lib/moneta/api/key_value_serializer.rb
moneta-api-1.12.2 lib/moneta/api/key_value_serializer.rb
moneta-api-1.12.1 lib/moneta/api/key_value_serializer.rb
moneta-api-1.12.0 lib/moneta/api/key_value_serializer.rb
moneta-api-1.11.0 lib/moneta/api/key_value_serializer.rb
moneta-api-1.10.0 lib/moneta/api/key_value_serializer.rb
moneta-api-1.9.0 lib/moneta/api/key_value_serializer.rb
moneta-api-1.8.0 lib/moneta/api/key_value_serializer.rb
moneta-api-1.7.0 lib/moneta/api/key_value_serializer.rb
moneta-api-1.6.0 lib/moneta/api/key_value_serializer.rb