Class: Bulkrax::NormalizedJson
- Inherits:
-
Object
- Object
- Bulkrax::NormalizedJson
- 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
-
.dump(value) ⇒ Object
When we write the serialized data to the database, we “dump” the value into that database column.
-
.load(string) ⇒ Object
When we load the serialized data from the database, we pass the database’s value into “load” function.
- .normalize_keys(hash) ⇒ Object
Class Method Details
.dump(value) ⇒ Object
When we write the serialized data to the database, we “dump” the value into that database column.
415 416 417 |
# File 'lib/bulkrax.rb', line 415 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
423 424 425 |
# File 'lib/bulkrax.rb', line 423 def self.load(string) normalize_keys(JSON.load(string)) end |
.normalize_keys(hash) ⇒ Object
404 405 406 407 408 409 410 411 |
# File 'lib/bulkrax.rb', line 404 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 |