cantino/huginn

View on GitHub
lib/json_with_indifferent_access.rb

Summary

Maintainability
A
0 mins
Test Coverage
class JsonWithIndifferentAccess
  def self.load(json)
    ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(json || '{}'))
  rescue JSON::ParserError
    Rails.logger.error "Unparsable JSON in JsonWithIndifferentAccess: #{json}"
    { 'error' => 'unparsable json detected during de-serialization' }
  end

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