Class: ActiveRecord::ConnectionAdapters::CipherStashPG::OID::Hstore
- Inherits:
-
Type::Value
- Object
- Type::Value
- ActiveRecord::ConnectionAdapters::CipherStashPG::OID::Hstore
- Includes:
- ActiveModel::Type::Helpers::Mutable
- Defined in:
- lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/hstore.rb,
lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/hstore.rb,
lib/active_record/connection_adapters/7.1/cipherstash_pg/oid/hstore.rb
Overview
:nodoc:
Constant Summary collapse
- ERROR =
"Invalid Hstore document: %s"
Instance Method Summary collapse
- #accessor ⇒ Object
-
#changed_in_place?(raw_old_value, new_value) ⇒ Boolean
Will compare the Hash equivalents of
raw_old_value
andnew_value
. - #deserialize(value) ⇒ Object
- #serialize(value) ⇒ Object
- #type ⇒ Object
Instance Method Details
#accessor ⇒ Object
38 39 40 |
# File 'lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/hstore.rb', line 38 def accessor ActiveRecord::Store::StringKeyedHashAccessor end |
#changed_in_place?(raw_old_value, new_value) ⇒ Boolean
Will compare the Hash equivalents of raw_old_value
and new_value
. By comparing hashes, this avoids an edge case where the order of the keys change between the two hashes, and they would not be marked as equal.
46 47 48 |
# File 'lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/hstore.rb', line 46 def changed_in_place?(raw_old_value, new_value) deserialize(raw_old_value) != new_value end |
#deserialize(value) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/hstore.rb', line 16 def deserialize(value) if value.is_a?(::String) ::Hash[value.scan(HstorePair).map { |k, v| v = v.upcase == "NULL" ? nil : v.gsub(/\A"(.*)"\Z/m, '\1').gsub(/\\(.)/, '\1') k = k.gsub(/\A"(.*)"\Z/m, '\1').gsub(/\\(.)/, '\1') [k, v] }] else value end end |
#serialize(value) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/hstore.rb', line 28 def serialize(value) if value.is_a?(::Hash) value.map { |k, v| "#{escape_hstore(k)}=>#{escape_hstore(v)}" }.join(", ") elsif value.respond_to?(:to_unsafe_h) serialize(value.to_unsafe_h) else value end end |
#type ⇒ Object
12 13 14 |
# File 'lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/hstore.rb', line 12 def type :hstore end |