Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore

Inherits:
Type::Value
  • Object
show all
Includes:
ActiveModel::Type::Helpers::Mutable
Defined in:
activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from ActiveModel::Type::Helpers::Mutable

#cast, #changed_in_place?

Instance Method Details

#accessorObject


34
35
36
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb', line 34

def accessor
  ActiveRecord::Store::StringKeyedHashAccessor
end

#deserialize(value) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb', line 12

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


24
25
26
27
28
29
30
31
32
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb', line 24

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

#typeObject


8
9
10
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/hstore.rb', line 8

def type
  :hstore
end