class Apes::Serializers::JSON

JSON encoded serialized value.

Public Class Methods

dump(data) click to toggle source

Saves serialized data.

@param data [Object] The data to serialize. @return [String] Serialized data.

# File lib/apes/serializers.rb, line 50
def self.dump(data)
  ActiveSupport::JSON.encode(data.as_json)
end
load(data, raise_errors = false, default = {}) click to toggle source

Saves serialized data.

@param data [String] The serialized data. @param raise_errors [Boolean] Whether to raise decoding errors. @param default [Object] A fallback value to return when not raising errors. @return [Object] A deserialized value.

# File lib/apes/serializers.rb, line 37
def self.load(data, raise_errors = false, default = {})
  data = ActiveSupport::JSON.decode(data)
  data = data.with_indifferent_access if data.is_a?(Hash)
  data
rescue => e
  raise(e) if raise_errors
  default
end