Class: Torque::PostgreSQL::Adapter::OID::Ltree
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- Torque::PostgreSQL::Adapter::OID::Ltree
- Defined in:
- lib/torque/postgresql/adapter/oid/ltree.rb,
sig/torque/postgresql/adapter/oid/ltree.rbs
Overview
Moves a label path between the shapes the gem accepts, its pure list of items and the text form PostgreSQL stores. Nothing is validated here, that is left to PostgreSQL
Direct Known Subclasses
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
- #cast(value) ⇒ path?
- #changed_in_place?(raw_old_value, new_value) ⇒ Boolean
- #deserialize(value) ⇒ path?
- #hash ⇒ Integer
- #items_for(value, sanitize: true) ⇒ ::Array[untyped]
- #serialize(value) ⇒ String?
- #type ⇒ :ltree
- #type_cast_for_schema(value) ⇒ String
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
46 47 48 |
# File 'lib/torque/postgresql/adapter/oid/ltree.rb', line 46 def ==(other) other.class == self.class end |
#cast(value) ⇒ path?
16 17 18 19 20 21 |
# File 'lib/torque/postgresql/adapter/oid/ltree.rb', line 16 def cast(value) return value if value.is_a?(value_class) return if value.blank? value_class.new(value) end |
#changed_in_place?(raw_old_value, new_value) ⇒ Boolean
42 43 44 |
# File 'lib/torque/postgresql/adapter/oid/ltree.rb', line 42 def changed_in_place?(raw_old_value, new_value) raw_old_value != serialize(new_value) end |
#deserialize(value) ⇒ path?
28 29 30 31 32 |
# File 'lib/torque/postgresql/adapter/oid/ltree.rb', line 28 def deserialize(value) return if value.nil? value_class.new(value, sanitize: false) end |
#hash ⇒ Integer
51 52 53 |
# File 'lib/torque/postgresql/adapter/oid/ltree.rb', line 51 def hash self.class.hash end |
#items_for(value, sanitize: true) ⇒ ::Array[untyped]
34 35 36 |
# File 'lib/torque/postgresql/adapter/oid/ltree.rb', line 34 def items_for(value, sanitize: true) ::Array.wrap(value).flat_map { |entry| items_of(entry, sanitize) } end |
#serialize(value) ⇒ String?
23 24 25 26 |
# File 'lib/torque/postgresql/adapter/oid/ltree.rb', line 23 def serialize(value) path = cast(value) path.map { |item| compile(item) }.join('.') unless path.nil? end |
#type ⇒ :ltree
12 13 14 |
# File 'lib/torque/postgresql/adapter/oid/ltree.rb', line 12 def type :ltree end |
#type_cast_for_schema(value) ⇒ String
38 39 40 |
# File 'lib/torque/postgresql/adapter/oid/ltree.rb', line 38 def type_cast_for_schema(value) serialize(value).inspect end |