Module: SerializableAttributes::Format::ActiveSupportJson

Extended by:
ActiveSupportJson
Included in:
ActiveSupportJson
Defined in:
lib/serializable_attributes/format/active_support_json.rb

Instance Method Summary collapse

Instance Method Details

#decode(body) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/serializable_attributes/format/active_support_json.rb', line 18

def decode(body)
  return {} if body.to_s.empty?
  s = StringIO.new(body)
  z = Zlib::GzipReader.new(s)
  hash = ActiveSupport::JSON.decode(z.read)
  z.close
  hash
end

#encode(body) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/serializable_attributes/format/active_support_json.rb', line 9

def encode(body)
  return nil if body.blank?
  s = StringIO.new
  z = Zlib::GzipWriter.new(s)
  z.write ActiveSupport::JSON.encode(body)
  z.close
  s.string
end