Class: Rasti::DB::TypeConverters::PostgresTypes::JSON
- Inherits:
-
Object
- Object
- Rasti::DB::TypeConverters::PostgresTypes::JSON
- Defined in:
- lib/rasti/db/type_converters/postgres_types/json.rb
Constant Summary collapse
- DB_TYPE_REGEX =
/^json$/
Class Method Summary collapse
- .from_db(value) ⇒ Object
- .from_db?(klass) ⇒ Boolean
- .to_db(value, type) ⇒ Object
- .to_db?(type) ⇒ Boolean
Class Method Details
.from_db(value) ⇒ Object
22 23 24 |
# 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) ⇒ Boolean
18 19 20 |
# 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) ⇒ Object
14 15 16 |
# 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) ⇒ Boolean
10 11 12 |
# File 'lib/rasti/db/type_converters/postgres_types/json.rb', line 10 def to_db?(type) !type.match(DB_TYPE_REGEX).nil? end |