Class: Torque::PostgreSQL::Attributes::LQuery
- Inherits:
-
Object
- Object
- Torque::PostgreSQL::Attributes::LQuery
- Defined in:
- lib/torque/postgresql/attributes/lquery.rb
Overview
A pattern that matches label paths, as described by the lquery data
type. It is only ever built from Ruby and never parsed back from its
text form, so each entry of the given list becomes one item
Constant Summary collapse
- MARKERS =
/[*|!{}@%]/- QUANTIFIER =
/\{(?:\d+|\d*,\d*)\}/- LABEL =
/[[:alnum:]_-]+/- ALTERNATIVE =
/#{LABEL}[@*%]{0,3}/- ITEM =
/\A!?#{ALTERNATIVE}(?:\|#{ALTERNATIVE})*#{QUANTIFIER}?\z/- STAR_ITEM =
/\A\*#{QUANTIFIER}?\z/
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Class Method Summary collapse
- .[](*items) ⇒ Object
-
.load(value) ⇒ Object
Values coming from the database are valid by construction.
-
.marker?(value) ⇒ Boolean
Whether the given value asks for a pattern instead of a plain path, which is what makes a condition use
~instead of=.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(items, normalize: true) ⇒ LQuery
constructor
A new instance of LQuery.
- #to_s ⇒ Object
Constructor Details
#initialize(items, normalize: true) ⇒ LQuery
Returns a new instance of LQuery.
49 50 51 52 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 49 def initialize(items, normalize: true) items = normalize ? (items) : Array.wrap(items) @items = normalize ? items.map { |item| compile(item) } : items.map(&:to_s) end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
47 48 49 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 47 def items @items end |
Class Method Details
.[](*items) ⇒ Object
18 19 20 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 18 def [](*items) new(items) end |
.load(value) ⇒ Object
Values coming from the database are valid by construction
23 24 25 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 23 def load(value) new(value, normalize: false) end |
.marker?(value) ⇒ Boolean
Whether the given value asks for a pattern instead of a plain path,
which is what makes a condition use ~ instead of =
29 30 31 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 29 def marker?(value) Array.wrap(value).any? { |item| item_marker?(item) } end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
58 59 60 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 58 def ==(other) other.is_a?(LQuery) && to_s == other.to_s end |
#hash ⇒ Object
63 64 65 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 63 def hash to_s.hash end |
#to_s ⇒ Object
54 55 56 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 54 def to_s items.join('.') end |