class Rasti::DB::TypeConverters::PostgresTypes::JSON

Constants

DB_TYPE_REGEX

Public Class Methods

from_db(value) click to toggle source
# File lib/rasti/db/type_converters/postgres_types/json.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/json.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/json.rb, line 14
def to_db(value, type)
  Sequel.pg_json value
end
to_db?(type) click to toggle source
# File lib/rasti/db/type_converters/postgres_types/json.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/json.rb, line 33
def to_array?(klass)
  defined?(Sequel::Postgres::JSONArray) &&
  klass == Sequel::Postgres::JSONArray
end
to_hash?(klass) click to toggle source
# File lib/rasti/db/type_converters/postgres_types/json.rb, line 28
def to_hash?(klass)
  defined?(Sequel::Postgres::JSONHash) &&
  klass == Sequel::Postgres::JSONHash
end