Class: Rasti::DB::TypeConverters::PostgresTypes::JSONB

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

Constant Summary collapse

DB_TYPE_REGEX =
/^jsonb$/

Class Method Summary collapse

Class Method Details

.from_db(value) ⇒ Object



22
23
24
# File 'lib/rasti/db/type_converters/postgres_types/jsonb.rb', line 22

def from_db(value)
  to_hash?(value.class) ? value.to_h : value.to_a
end

.from_db?(klass) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rasti/db/type_converters/postgres_types/jsonb.rb', line 18

def from_db?(klass)
  to_hash?(klass) || to_array?(klass)
end

.to_db(value, type) ⇒ Object



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

def to_db(value, type)
  Sequel.pg_jsonb value
end

.to_db?(type) ⇒ Boolean

Returns:

  • (Boolean)


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

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