Class: Cyrel::Expression::Base

Inherits:
Object
  • Object
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.

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) # Use <> for Cypher inequality
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) # Use = for Cypher equality
end

#=~(other) ⇒ Object



45
46
47
# File 'lib/cyrel/expression/base.rb', line 45

def =~(other)
  Comparison.new(self, :=~, other) # Regex match
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) # Exponentiation
end

#render(query) ⇒ String

Renders the expression into its Cypher string representation. Subclasses must implement this method.

Parameters:

  • query (Cyrel::Query)

    The query object, used for parameter registration if needed.

Returns:

  • (String)

    The Cypher string fragment for the expression.

Raises:

  • (NotImplementedError)


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