Class: Rasti::DB::TypeConverters::PostgresTypes::Array

Inherits:
Object
  • Object
show all
Defined in:
lib/rasti/db/type_converters/postgres_types/array.rb

Constant Summary collapse

DB_TYPE_REGEX =
/^([a-z]+)\[\]$/

Class Method Summary collapse

Class Method Details

.from_db(value) ⇒ Object



25
26
27
# File 'lib/rasti/db/type_converters/postgres_types/array.rb', line 25

def from_db(value)
  value.to_a
end

.from_db?(klass) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/rasti/db/type_converters/postgres_types/array.rb', line 20

def from_db?(klass)
  defined?(Sequel::Postgres::PGArray) &&
  klass == Sequel::Postgres::PGArray
end

.to_db(value, type) ⇒ Object



14
15
16
17
18
# File 'lib/rasti/db/type_converters/postgres_types/array.rb', line 14

def to_db(value, type)
  sub_type = type[0..-3]
  array = sub_type == 'hstore' ? value.map { |v| Sequel.hstore v } : value
  Sequel.pg_array array, sub_type
end

.to_db?(type) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/rasti/db/type_converters/postgres_types/array.rb', line 10

def to_db?(type)
  !type.match(DB_TYPE_REGEX).nil?
end