Class: Moneta::Api::KeyValueSerializer
- Inherits:
-
Object
- Object
- Moneta::Api::KeyValueSerializer
- Defined in:
- lib/moneta/api/key_value_serializer.rb
Class Method Summary collapse
Class Method Details
.deserialize(attributes) ⇒ Object
16 17 18 19 20 |
# File 'lib/moneta/api/key_value_serializer.rb', line 16 def deserialize(attributes) attributes.each_with_object({}) do |attribute, hash| hash[attribute[:key].to_sym] = attribute.tap { |a| a.delete(:key) } end end |
.serialize(entity) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/moneta/api/key_value_serializer.rb', line 5 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 |