Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array
- Inherits:
-
Type::Value
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array
- Includes:
- Mutable
- Defined in:
- lib/active_record/connection_adapters/postgresql/oid/array.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#delimiter ⇒ Object
readonly
Returns the value of attribute delimiter.
-
#subtype ⇒ Object
readonly
Returns the value of attribute subtype.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cast(value) ⇒ Object
- #deserialize(value) ⇒ Object
-
#initialize(subtype, delimiter = ',') ⇒ Array
constructor
A new instance of Array.
- #map(value, &block) ⇒ Object
- #serialize(value) ⇒ Object
- #type_cast_for_schema(value) ⇒ Object
Constructor Details
#initialize(subtype, delimiter = ',') ⇒ Array
Returns a new instance of Array.
11 12 13 14 15 16 17 |
# File 'lib/active_record/connection_adapters/postgresql/oid/array.rb', line 11 def initialize(subtype, delimiter = ',') @subtype = subtype @delimiter = delimiter @pg_encoder = PG::TextEncoder::Array.new name: "#{type}[]", delimiter: delimiter @pg_decoder = PG::TextDecoder::Array.new name: "#{type}[]", delimiter: delimiter end |
Instance Attribute Details
#delimiter ⇒ Object (readonly)
Returns the value of attribute delimiter.
8 9 10 |
# File 'lib/active_record/connection_adapters/postgresql/oid/array.rb', line 8 def delimiter @delimiter end |
#subtype ⇒ Object (readonly)
Returns the value of attribute subtype.
8 9 10 |
# File 'lib/active_record/connection_adapters/postgresql/oid/array.rb', line 8 def subtype @subtype end |
Instance Method Details
#==(other) ⇒ Object
42 43 44 45 46 |
# File 'lib/active_record/connection_adapters/postgresql/oid/array.rb', line 42 def ==(other) other.is_a?(Array) && subtype == other.subtype && delimiter == other.delimiter end |
#cast(value) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/active_record/connection_adapters/postgresql/oid/array.rb', line 27 def cast(value) if value.is_a?(::String) value = @pg_decoder.decode(value) end type_cast_array(value, :cast) end |
#deserialize(value) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/active_record/connection_adapters/postgresql/oid/array.rb', line 19 def deserialize(value) if value.is_a?(::String) type_cast_array(@pg_decoder.decode(value), :deserialize) else super end end |
#map(value, &block) ⇒ Object
53 54 55 |
# File 'lib/active_record/connection_adapters/postgresql/oid/array.rb', line 53 def map(value, &block) value.map(&block) end |
#serialize(value) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/active_record/connection_adapters/postgresql/oid/array.rb', line 34 def serialize(value) if value.is_a?(::Array) @pg_encoder.encode(type_cast_array(value, :serialize)) else super end end |
#type_cast_for_schema(value) ⇒ Object
48 49 50 51 |
# File 'lib/active_record/connection_adapters/postgresql/oid/array.rb', line 48 def type_cast_for_schema(value) return super unless value.is_a?(::Array) "[" + value.map { |v| subtype.type_cast_for_schema(v) }.join(", ") + "]" end |