Class: Rebel::SQL::Raw

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

Instance Method Summary collapse

Instance Method Details

#and(*clause) ⇒ Object Also known as: &



105
106
107
# File 'lib/rebel/sql.rb', line 105

def and(*clause)
  Raw.new("#{self.parens?} AND #{Rebel::SQL.and_clause(*clause)}")
end

#as(n) ⇒ Object



77
78
79
# File 'lib/rebel/sql.rb', line 77

def as(n)
  Raw.new(self + " AS #{Rebel::SQL.name(n)}")
end

#as?(n) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/rebel/sql.rb', line 81

def as?(n)
  n ? as(n) : self
end

#ascObject



97
98
99
# File 'lib/rebel/sql.rb', line 97

def asc
  Raw.new(self + " ASC")
end

#descObject



101
102
103
# File 'lib/rebel/sql.rb', line 101

def desc
  Raw.new(self + " DESC")
end

#eq(n) ⇒ Object Also known as: ==, is



115
116
117
118
119
120
121
122
# File 'lib/rebel/sql.rb', line 115

def eq(n)
  case n
  when nil
    Raw.new("#{self} IS NULL")
  else
    Raw.new("#{self} = #{Rebel::SQL.name_or_value(n)}")
  end
end

#ge(n) ⇒ Object Also known as: >=



152
153
154
# File 'lib/rebel/sql.rb', line 152

def ge(n)
  Raw.new("#{self} >= #{Rebel::SQL.name_or_value(n)}")
end

#gt(n) ⇒ Object Also known as: >



142
143
144
# File 'lib/rebel/sql.rb', line 142

def gt(n)
  Raw.new("#{self} > #{Rebel::SQL.name_or_value(n)}")
end

#having(*clause) ⇒ Object



93
94
95
# File 'lib/rebel/sql.rb', line 93

def having(*clause)
  Raw.new(self + " HAVING #{Rebel::SQL.and_clause(*clause)}")
end

#in(*v) ⇒ Object



157
158
159
# File 'lib/rebel/sql.rb', line 157

def in(*v)
  Raw.new("#{self} IN (#{Rebel::SQL.values(*v)})")
end

#le(n) ⇒ Object Also known as: <=



147
148
149
# File 'lib/rebel/sql.rb', line 147

def le(n)
  Raw.new("#{self} <= #{Rebel::SQL.name_or_value(n)}")
end

#like(n) ⇒ Object



165
166
167
# File 'lib/rebel/sql.rb', line 165

def like(n)
  Raw.new("#{self} LIKE #{Rebel::SQL.value(n)}")
end

#lt(n) ⇒ Object Also known as: <



137
138
139
# File 'lib/rebel/sql.rb', line 137

def lt(n)
  Raw.new("#{self} < #{Rebel::SQL.name_or_value(n)}")
end

#ne(n) ⇒ Object Also known as: !=, is_not



126
127
128
129
130
131
132
133
# File 'lib/rebel/sql.rb', line 126

def ne(n)
  case n
  when nil
    Raw.new("#{self} IS NOT NULL")
  else
    Raw.new("#{self} != #{Rebel::SQL.name_or_value(n)}")
  end
end

#not_in(*v) ⇒ Object



161
162
163
# File 'lib/rebel/sql.rb', line 161

def not_in(*v)
  Raw.new("#{self} NOT IN (#{Rebel::SQL.values(*v)})")
end

#not_like(n) ⇒ Object



169
170
171
# File 'lib/rebel/sql.rb', line 169

def not_like(n)
  Raw.new("#{self} NOT LIKE #{Rebel::SQL.value(n)}")
end

#on(*clause) ⇒ Object



85
86
87
# File 'lib/rebel/sql.rb', line 85

def on(*clause)
  Raw.new(self + " ON #{Rebel::SQL.and_clause(*clause)}")
end

#on?(*clause) ⇒ Boolean

Returns:

  • (Boolean)


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

def on?(*clause)
  clause.any? ? on(*clause) : self
end

#or(*clause) ⇒ Object Also known as: |



110
111
112
# File 'lib/rebel/sql.rb', line 110

def or(*clause)
  Raw.new("#{self} OR #{Rebel::SQL.and_clause(*clause)}").wants_parens!
end

#parensObject



69
70
71
# File 'lib/rebel/sql.rb', line 69

def parens
  Raw.new("(#{self})")
end

#parens?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/rebel/sql.rb', line 73

def parens?
  wants_parens? ? parens : self
end

#wants_parens!Object



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

def wants_parens!
  @wants_parens = true
  self
end

#wants_parens?Boolean

Returns:

  • (Boolean)


64
65
66
67
# File 'lib/rebel/sql.rb', line 64

def wants_parens?
  @wants_parens = false unless instance_variable_defined?(:@wants_parens)
  @wants_parens
end