Class: Torque::PostgreSQL::Attributes::LQuery

Inherits:
Object
  • Object
show all
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 =

Returns:

  • (Regexp)
/[*|!{}@%]/
LEVEL =

Returns:

  • (Regexp)
/\A(?<not>!)?(?<variants>.*?)(?:\{(?<min>\d*)(?<comma>,)?(?<max>\d*)\})?\z/
VARIANT =

Returns:

  • (Regexp)
/\A(?<name>.*?)(?<modifiers>[*@%]*)\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil, sanitize: true) ⇒ LQuery

Returns a new instance of LQuery.

Parameters:

  • value (Object) (defaults to: nil)
  • sanitize: (Boolean) (defaults to: true)


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.

Returns:

  • (Array[untyped])


17
18
19
# File 'lib/torque/postgresql/attributes/lquery.rb', line 17

def items
  @items
end

Class Method Details

.[](*items) ⇒ instance

Parameters:

  • items (Object)

Returns:

  • (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?

Parameters:

  • other (Object)

Returns:

  • (Boolean)


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?

Parameters:

Returns:

  • (Integer, nil)


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

Parameters:

  • (Object)

Returns:

  • (Object)


19
# File 'sig/torque/postgresql/attributes/lquery.rbs', line 19

def []: (*untyped) -> untyped

#each {|arg0| ... } ⇒ Object

Parameters:

  • (Object)

Yields:

Yield Parameters:

  • arg0 (Object)

Yield Returns:

  • (Object)

Returns:

  • (Object)


16
# File 'sig/torque/postgresql/attributes/lquery.rbs', line 16

def each: (*untyped) ?{ (untyped) -> untyped } -> untyped

#empty? ⇒ Boolean

Returns:

  • (Boolean)


18
# File 'sig/torque/postgresql/attributes/lquery.rbs', line 18

def empty?: () -> bool

#hash ⇒ Integer

Returns:

  • (Integer)


58
59
60
# File 'lib/torque/postgresql/attributes/lquery.rb', line 58

def hash
  items.hash
end

#inspect ⇒ String

Returns:

  • (String)


15
# File 'sig/torque/postgresql/attributes/lquery.rbs', line 15

def inspect: () -> String

#match?(path) ⇒ Boolean

Parameters:

Returns:

  • (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

Returns:

  • (Regexp)


38
39
40
# File 'lib/torque/postgresql/attributes/lquery.rb', line 38

def pattern
  @pattern ||= compile
end

#pattern? ⇒ Boolean

Returns:

  • (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

Returns:

  • (Integer)


17
# File 'sig/torque/postgresql/attributes/lquery.rbs', line 17

def size: () -> Integer

#to_s ⇒ String

Returns:

  • (String)


30
31
32
# File 'lib/torque/postgresql/attributes/lquery.rb', line 30

def to_s
  type.serialize(self)
end