Class: Bulkrax::NormalizedJson

Inherits:
Object
  • Object
show all
Defined in:
lib/bulkrax.rb

Overview

This class confirms to the Active::Support.serialize interface. It’s job is to ensure that we don’t have keys with the tricksy Byte Order Mark character.

Class Method Summary collapse

Class Method Details

.dump(value) ⇒ Object

When we write the serialized data to the database, we “dump” the value into that database column.



295
296
297
# File 'lib/bulkrax.rb', line 295

def self.dump(value)
  JSON.dump(normalize_keys(value))
end

.load(string) ⇒ Object

When we load the serialized data from the database, we pass the database’s value into “load” function.

rubocop:disable Security/JSONLoad



303
304
305
# File 'lib/bulkrax.rb', line 303

def self.load(string)
  normalize_keys(JSON.load(string))
end

.normalize_keys(hash) ⇒ Object



284
285
286
287
288
289
290
291
# File 'lib/bulkrax.rb', line 284

def self.normalize_keys(hash)
  return hash unless hash.respond_to?(:each_pair)
  returning_value = {}
  hash.each_pair do |key, value|
    returning_value[Bulkrax.normalize_string(key)] = value
  end
  returning_value
end