Class: BinaryOperation
Instance Attribute Summary collapse
-
#left ⇒ Object
Returns the value of attribute left.
-
#op ⇒ Object
Returns the value of attribute op.
-
#right ⇒ Object
Returns the value of attribute right.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(left, op, right) ⇒ BinaryOperation
constructor
A new instance of BinaryOperation.
- #ref_sql ⇒ Object
- #state ⇒ Object
Methods inherited from Expr
#*, #+, #<, #<=, #>, #>=, #and, #asc, #desc, #eq, #in, #minus, #ne, #not, #plus
Constructor Details
#initialize(left, op, right) ⇒ BinaryOperation
110 111 112 113 114 |
# File 'lib/lilit_sql.rb', line 110 def initialize(left, op, right) @left = left @op = op @right = lit(right) end |
Instance Attribute Details
#left ⇒ Object
Returns the value of attribute left.
108 109 110 |
# File 'lib/lilit_sql.rb', line 108 def left @left end |
#op ⇒ Object
Returns the value of attribute op.
108 109 110 |
# File 'lib/lilit_sql.rb', line 108 def op @op end |
#right ⇒ Object
Returns the value of attribute right.
108 109 110 |
# File 'lib/lilit_sql.rb', line 108 def right @right end |
Instance Method Details
#==(other) ⇒ Object
136 137 138 |
# File 'lib/lilit_sql.rb', line 136 def ==(other) other.class == self.class && other.state == state end |
#ref_sql ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/lilit_sql.rb', line 116 def ref_sql if @right.is_a?(Literal) && @right.value.nil? return ( if @op == :'=' "#{@left.ref_sql} is #{@right.ref_sql}" elsif @op == :!= "#{@left.ref_sql} is not #{@right.ref_sql}" else raise ArgumentError.new("Nil doesn't support the operator: #{@op}") end ) end if @op == :in return "#{@left.ref_sql} in (#{@right.map(&:ref_sql).join(', ')})" end "#{@left.ref_sql} #{@op} #{@right.ref_sql}" end |
#state ⇒ Object
140 141 142 |
# File 'lib/lilit_sql.rb', line 140 def state instance_variables.map { |variable| instance_variable_get variable } end |