Class: PandaPal::Session::DataSerializer

Inherits:
Object
  • Object
show all
Defined in:
app/models/panda_pal/session.rb

Class Method Summary collapse

Class Method Details

.dump(obj) ⇒ Object



414
415
416
# File 'app/models/panda_pal/session.rb', line 414

def self.dump(obj)
  JSON.dump(obj)
end

.load(str) ⇒ Object



404
405
406
407
408
409
410
411
412
# File 'app/models/panda_pal/session.rb', line 404

def self.load(str)
  return {}.with_indifferent_access unless str.present?
  begin
    parsed = JSON.parse(str)
  rescue JSON::ParserError
    parsed = yaml_load(str)
  end
  parsed.is_a?(Hash) ? HashWithIndifferentAccess.new(parsed) : parsed
end

.yaml_load(payload) ⇒ Object



421
422
423
# File 'app/models/panda_pal/session.rb', line 421

def self.yaml_load(payload)
  YAML.unsafe_load(payload)
end