Class: EmbeddedLocalization::Storage::Hstore

Inherits:
ActiveRecord::Type::Value
  • Object
show all
Includes:
ActiveModel::Type::Helpers::Mutable
Defined in:
lib/embedded_localization/storage/hstore.rb

Overview

ActiveRecord attribute type for a PostgreSQL hstore i18n column.

hstore is a flat String => String map, so each translation is stored under the key ".", e.g. "de.name" => "Science-Fiction". In Ruby the gem works with the nested Hash {name: "Science-Fiction"}. Reading and writing the hstore text format is delegated to ActiveRecord's own hstore type.

Constant Summary collapse

SEPARATOR =
'.'.freeze

Instance Method Summary collapse

Instance Method Details

#changed_in_place?(raw_old_value, new_value) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/embedded_localization/storage/hstore.rb', line 25

def changed_in_place?(raw_old_value, new_value)
  deserialize(raw_old_value) != new_value
end

#deserialize(value) ⇒ Object



17
18
19
# File 'lib/embedded_localization/storage/hstore.rb', line 17

def deserialize(value)
  nest(hstore.deserialize(value))
end

#serialize(value) ⇒ Object



21
22
23
# File 'lib/embedded_localization/storage/hstore.rb', line 21

def serialize(value)
  hstore.serialize(flatten(value))
end

#typeObject



13
14
15
# File 'lib/embedded_localization/storage/hstore.rb', line 13

def type
  :hstore
end