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



360
361
362
# File 'app/models/panda_pal/session.rb', line 360

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

.load(str) ⇒ Object



350
351
352
353
354
355
356
357
358
# File 'app/models/panda_pal/session.rb', line 350

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



367
368
369
# File 'app/models/panda_pal/session.rb', line 367

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