Class: Sequel::SQL::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/sql.rb

Overview

Base class for all SQL fragments

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attr_reader(*args) ⇒ Object

all instance variables declared to be readers are to be used for comparison.



54
55
56
57
# File 'lib/sequel/sql.rb', line 54

def self.attr_reader(*args)
  super
  comparison_attrs.concat args
end

.comparison_attrsObject



59
60
61
# File 'lib/sequel/sql.rb', line 59

def self.comparison_attrs
  @comparison_attrs ||= self == Expression ? [] : superclass.comparison_attrs.clone
end

Instance Method Details

#==(other) ⇒ Object

Alias of eql?



72
73
74
# File 'lib/sequel/sql.rb', line 72

def ==(other)
  eql?(other)
end

#eql?(other) ⇒ Boolean

Returns true if the receiver is the same expression as the the other expression.

Returns:

  • (Boolean)


78
79
80
# File 'lib/sequel/sql.rb', line 78

def eql?(other)
  other.is_a?(self.class) && !self.class.comparison_attrs.find {|a| send(a) != other.send(a)}
end

#hashObject

Make sure that the hash value is the same if the attributes are the same.



83
84
85
# File 'lib/sequel/sql.rb', line 83

def hash
  ([self.class] + self.class.comparison_attrs.map{|x| send(x)}).hash
end

#litObject

Returns self, because SQL::Expression already acts like LiteralString.



89
90
91
# File 'lib/sequel/sql.rb', line 89

def lit
  self
end

#sql_literal(ds) ⇒ Object

Alias of to_s



94
95
96
# File 'lib/sequel/sql.rb', line 94

def sql_literal(ds)
  to_s(ds)
end