Class: Cyrel::Expression::Base
- Inherits:
-
Object
- Object
- Cyrel::Expression::Base
show all
- Defined in:
- lib/cyrel/expression/base.rb
Overview
Base class/module for all expression types. Defines the common interface, primarily the ‘render` method.
Direct Known Subclasses
Clause::Return::RawIdentifier, Clause::With::RawExpressionString, Alias, Case, Comparison, Exists, FunctionCall, Literal, Logical, Operator, PatternComprehension, PropertyAccess
Instance Method Summary
collapse
Instance Method Details
#!=(other) ⇒ Object
alias_method must be called at the class level, not inside a method
41
42
43
|
# File 'lib/cyrel/expression/base.rb', line 41
def !=(other)
Comparison.new(self, :'<>', other) end
|
#%(other) ⇒ Object
65
66
67
|
# File 'lib/cyrel/expression/base.rb', line 65
def %(other)
Operator.new(self, :%, other)
end
|
#&(other) ⇒ Object
Logical operators require special handling as Ruby’s ‘and`, `or`, `not` have different precedence and short-circuiting behavior. We use `&` for AND and `|` for OR. `!` is handled separately if needed.
79
80
81
|
# File 'lib/cyrel/expression/base.rb', line 79
def &(other)
Logical.new(self, :AND, other)
end
|
#*(other) ⇒ Object
57
58
59
|
# File 'lib/cyrel/expression/base.rb', line 57
def *(other)
Operator.new(self, :*, other)
end
|
#+(other) ⇒ Object
49
50
51
|
# File 'lib/cyrel/expression/base.rb', line 49
def +(other)
Operator.new(self, :+, other)
end
|
#-(other) ⇒ Object
53
54
55
|
# File 'lib/cyrel/expression/base.rb', line 53
def -(other)
Operator.new(self, :-, other)
end
|
#/(other) ⇒ Object
61
62
63
|
# File 'lib/cyrel/expression/base.rb', line 61
def /(other)
Operator.new(self, :/, other)
end
|
#<(other) ⇒ Object
28
29
30
|
# File 'lib/cyrel/expression/base.rb', line 28
def <(other)
Comparison.new(self, :<, other)
end
|
#<=(other) ⇒ Object
32
33
34
|
# File 'lib/cyrel/expression/base.rb', line 32
def <=(other)
Comparison.new(self, :<=, other)
end
|
#==(other) ⇒ Object
Also known as:
eq
36
37
38
|
# File 'lib/cyrel/expression/base.rb', line 36
def ==(other)
Comparison.new(self, :'=', other) end
|
#=~(other) ⇒ Object
45
46
47
|
# File 'lib/cyrel/expression/base.rb', line 45
def =~(other)
Comparison.new(self, :=~, other) end
|
#>(other) ⇒ Object
— Operator Overloading for DSL — These methods allow building expression trees more naturally, e.g., Cyrel.prop(:n, :age) > 18
20
21
22
|
# File 'lib/cyrel/expression/base.rb', line 20
def >(other)
Comparison.new(self, :>, other)
end
|
#>=(other) ⇒ Object
24
25
26
|
# File 'lib/cyrel/expression/base.rb', line 24
def >=(other)
Comparison.new(self, :>=, other)
end
|
#^(other) ⇒ Object
69
70
71
|
# File 'lib/cyrel/expression/base.rb', line 69
def ^(other)
Operator.new(self, :^, other) end
|
#render(query) ⇒ String
Renders the expression into its Cypher string representation. Subclasses must implement this method.
12
13
14
|
# File 'lib/cyrel/expression/base.rb', line 12
def render(query)
raise NotImplementedError, "#{self.class} must implement the 'render' method"
end
|
#|(other) ⇒ Object
83
84
85
|
# File 'lib/cyrel/expression/base.rb', line 83
def |(other)
Logical.new(self, :OR, other)
end
|