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



43
44
45
# File 'app/models/panda_pal/session.rb', line 43

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

.load(str) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'app/models/panda_pal/session.rb', line 33

def self.load(str)
  return {} 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