Module: Netfira::WebConnect::Model::Record::Serializer

Extended by:
ActiveSupport::Concern
Included in:
Netfira::WebConnect::Model::Record
Defined in:
lib/netfira/web_connect/model/record/serializer.rb

Constant Summary collapse

EXCLUDE_FROM_SERIALIZE =
%w[id shop_id digest delivery_status created_at updated_at deleted_at]

Instance Method Summary collapse

Instance Method Details

#to_sObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/netfira/web_connect/model/record/serializer.rb', line 26

def to_s

  # Map each array of keys from the above method into a sorted hash of key/value pairs
  data = self.class.attributes_to_serialize.map do |keys|
    pairs = keys.sort.map do |key|
      [key.camelize(:lower), cast_for_serialization(__send__ key)]
    end
    pairs.reject!{ |v| v[1].nil? }.to_h
  end

  # Return the class name and the sets above, e.g. Product{...},{...},{...}
  self.class.name.demodulize << JSON.generate(data)[1..-2]
end