Class: Torque::PostgreSQL::Attributes::LQuery
- Inherits:
-
Object
- Object
- Torque::PostgreSQL::Attributes::LQuery
- Includes:
- Enumerable
- Defined in:
- lib/torque/postgresql/attributes/lquery.rb,
sig/torque/postgresql/attributes/lquery.rbs
Overview
A pattern that matches label paths, as described by the lquery data
type. It holds the pure items of the pattern: labels as Strings, :any
for a star, a Range for a quantified star and an Array for a group of
alternatives
Constant Summary collapse
- MARKERS =
/[*|!{}@%]/- LEVEL =
/\A(?<not>!)?(?<variants>.*?)(?:\{(?<min>\d*)(?<comma>,)?(?<max>\d*)\})?\z/- VARIANT =
/\A(?<name>.*?)(?<modifiers>[*@%]*)\z/
Instance Attribute Summary collapse
-
#items ⇒ Array[untyped]
readonly
Returns the value of attribute items.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean (also: #eql?)
- #=~(path) ⇒ Integer?
- #[] ⇒ Object
- #each {|arg0| ... } ⇒ Object
- #empty? ⇒ Boolean
- #hash ⇒ Integer
-
#initialize(value = nil, sanitize: true) ⇒ LQuery
constructor
A new instance of LQuery.
- #inspect ⇒ String
- #match?(path) ⇒ Boolean
- #pattern ⇒ Regexp
- #pattern? ⇒ Boolean
- #size ⇒ Integer
- #to_s ⇒ String
Constructor Details
#initialize(value = nil, sanitize: true) ⇒ LQuery
Returns a new instance of LQuery.
26 27 28 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 26 def initialize(value = nil, sanitize: true) @items = type.items_for(value, sanitize: sanitize).freeze end |
Instance Attribute Details
#items ⇒ Array[untyped] (readonly)
Returns the value of attribute items.
17 18 19 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 17 def items @items end |
Class Method Details
.[](*items) ⇒ instance
22 23 24 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 22 def self.[](*items) new(items) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
52 53 54 55 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 52 def ==(other) other = other.items if other.is_a?(self.class) other.is_a?(::Array) && items == other end |
#=~(path) ⇒ Integer?
47 48 49 50 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 47 def =~(path) path = LTree.new(path) unless path.is_a?(LTree) pattern =~ path.to_s end |
#[] ⇒ Object
19 |
# File 'sig/torque/postgresql/attributes/lquery.rbs', line 19
def []: (*untyped) -> untyped
|
#each {|arg0| ... } ⇒ Object
16 |
# File 'sig/torque/postgresql/attributes/lquery.rbs', line 16
def each: (*untyped) ?{ (untyped) -> untyped } -> untyped
|
#empty? ⇒ Boolean
18 |
# File 'sig/torque/postgresql/attributes/lquery.rbs', line 18
def empty?: () -> bool
|
#hash ⇒ Integer
58 59 60 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 58 def hash items.hash end |
#inspect ⇒ String
15 |
# File 'sig/torque/postgresql/attributes/lquery.rbs', line 15
def inspect: () -> String
|
#match?(path) ⇒ Boolean
42 43 44 45 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 42 def match?(path) path = LTree.new(path) unless path.is_a?(LTree) pattern.match?(path.to_s) end |
#pattern ⇒ Regexp
38 39 40 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 38 def pattern @pattern ||= compile end |
#pattern? ⇒ Boolean
34 35 36 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 34 def pattern? items.any? { |item| !item.is_a?(::String) || item.match?(MARKERS) } end |
#size ⇒ Integer
17 |
# File 'sig/torque/postgresql/attributes/lquery.rbs', line 17
def size: () -> Integer
|
#to_s ⇒ String
30 31 32 |
# File 'lib/torque/postgresql/attributes/lquery.rb', line 30 def to_s type.serialize(self) end |