class Rasti::DB::TypeConverters::PostgresTypes::JSONB

Constants

DB_TYPE_REGEX

Public Class Methods

from_db(value) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/rasti/db/type_converters/postgres_types/jsonb.rb, line 10
def to_db?(type)
  !type.match(DB_TYPE_REGEX).nil?
end

Private Class Methods

to_array?(klass) click to toggle source
# File lib/rasti/db/type_converters/postgres_types/jsonb.rb, line 33
def to_array?(klass)
  defined?(Sequel::Postgres::JSONBArray) &&
  klass == Sequel::Postgres::JSONBArray
end
to_hash?(klass) click to toggle source
# File lib/rasti/db/type_converters/postgres_types/jsonb.rb, line 28
def to_hash?(klass)
  defined?(Sequel::Postgres::JSONBHash) &&
  klass == Sequel::Postgres::JSONBHash
end