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.



383
384
385
# File 'lib/bulkrax.rb', line 383

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



391
392
393
# File 'lib/bulkrax.rb', line 391

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

.normalize_keys(hash) ⇒ Object



372
373
374
375
376
377
378
379
# File 'lib/bulkrax.rb', line 372

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