Class: DataMapper::Property::PgHStore

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-postgres-types/property/pg_hstore.rb

Instance Method Summary collapse

Instance Method Details

#dump(value) ⇒ Object



16
17
18
19
20
21
# File 'lib/dm-postgres-types/property/pg_hstore.rb', line 16

def dump(value)
  return "" unless value
  value.map! do |idx, val|
    [escape_double_quote(idx), escape_value(val)].join(",")
  end
end

#load(value) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/dm-postgres-types/property/pg_hstore.rb', line 8

def load(value)
  return nil unless value
  values = value.split(",")
  values.map! { |val| unescape_pg_hash(val) }
  values.map! { |key, val| [key, unescape_nil(val)] }
  Hash[*(values.flatten)]
end