Class: Querly::Pattern::Expr::Constant
- Defined in:
- lib/querly/pattern/expr.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path:) ⇒ Constant
constructor
A new instance of Constant.
- #test_constant(node, path) ⇒ Object
- #test_node(node) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(path:) ⇒ Constant
Returns a new instance of Constant.
45 46 47 |
# File 'lib/querly/pattern/expr.rb', line 45 def initialize(path:) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
43 44 45 |
# File 'lib/querly/pattern/expr.rb', line 43 def path @path end |
Instance Method Details
#test_constant(node, path) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/querly/pattern/expr.rb', line 57 def test_constant(node, path) if node case node.type when :const parent = node.children[0] name = node.children[1] if name == path.last path.count == 1 || test_constant(parent, path.take(path.count - 1)) end when :cbase path.empty? end else path.empty? end end |
#test_node(node) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/querly/pattern/expr.rb', line 49 def test_node(node) if path test_constant node, path else node&.type == :const end end |