1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00
paper-trail-gem--paper_trail/spec/support/custom_json_serializer.rb

16 lines
413 B
Ruby
Raw Normal View History

2017-12-10 23:05:11 -05:00
# frozen_string_literal: true
# This custom serializer excludes nil values
module CustomJsonSerializer
extend PaperTrail::Serializers::JSON
def self.load(string)
parsed_value = super(string)
2016-02-15 20:25:11 -05:00
parsed_value.is_a?(Hash) ? parsed_value.reject { |k, v| k.blank? || v.blank? } : parsed_value
end
def self.dump(object)
2016-02-15 20:25:11 -05:00
object.is_a?(Hash) ? super(object.reject { |_k, v| v.nil? }) : super
end
2016-02-15 20:25:11 -05:00
end