Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore
- Inherits:
-
Type::Value
- Object
- Type::Value
- ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore
- Includes:
- Type::Mutable
- Defined in:
- lib/active_record/connection_adapters/postgresql/oid/hstore.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from Type::Value
Instance Method Summary collapse
- #accessor ⇒ Object
- #type ⇒ Object
- #type_cast_for_database(value) ⇒ Object
- #type_cast_from_database(value) ⇒ Object
Methods included from Type::Mutable
#changed_in_place?, #type_cast_from_user
Methods inherited from Type::Value
#==, #binary?, #changed?, #changed_in_place?, #initialize, #klass, #number?, #text?, #type_cast_for_schema, #type_cast_from_user
Constructor Details
This class inherits a constructor from ActiveRecord::Type::Value
Instance Method Details
#accessor ⇒ Object
32 33 34 |
# File 'lib/active_record/connection_adapters/postgresql/oid/hstore.rb', line 32 def accessor ActiveRecord::Store::StringKeyedHashAccessor end |
#type ⇒ Object
8 9 10 |
# File 'lib/active_record/connection_adapters/postgresql/oid/hstore.rb', line 8 def type :hstore end |
#type_cast_for_database(value) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/active_record/connection_adapters/postgresql/oid/hstore.rb', line 24 def type_cast_for_database(value) if value.is_a?(::Hash) value.map { |k, v| "#{escape_hstore(k)}=>#{escape_hstore(v)}" }.join(', ') else value end end |
#type_cast_from_database(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_record/connection_adapters/postgresql/oid/hstore.rb', line 12 def type_cast_from_database(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 |