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



185
186
187
# File 'app/models/panda_pal/session.rb', line 185

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

.load(str) ⇒ Object



175
176
177
178
179
180
181
182
183
# File 'app/models/panda_pal/session.rb', line 175

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