Module: Arel::Predications

Included in:
Attributes::Attribute, Nodes::InfixOperation, Nodes::NodeExpression, Nodes::SqlLiteral
Defined in:
activerecord/lib/arel/predications.rb

Instance Method Summary collapse

Instance Method Details

#between(other) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'activerecord/lib/arel/predications.rb', line 37

def between(other)
  if unboundable?(other.begin) == 1 || unboundable?(other.end) == -1
    self.in([])
  elsif other.begin.nil? || open_ended?(other.begin)
    if other.end.nil? || open_ended?(other.end)
      not_in([])
    elsif other.exclude_end?
      lt(other.end)
    else
      lteq(other.end)
    end
  elsif other.end.nil? || open_ended?(other.end)
    gteq(other.begin)
  elsif other.exclude_end?
    gteq(other.begin).and(lt(other.end))
  else
    left = quoted_node(other.begin)
    right = quoted_node(other.end)
    Nodes::Between.new(self, left.and(right))
  end
end

#concat(other) ⇒ Object



219
220
221
# File 'activerecord/lib/arel/predications.rb', line 219

def concat(other)
  Nodes::Concat.new self, other
end

#does_not_match(other, escape = nil, case_sensitive = false) ⇒ Object



151
152
153
# File 'activerecord/lib/arel/predications.rb', line 151

def does_not_match(other, escape = nil, case_sensitive = false)
  Nodes::DoesNotMatch.new self, quoted_node(other), escape, case_sensitive
end

#does_not_match_all(others, escape = nil) ⇒ Object



163
164
165
# File 'activerecord/lib/arel/predications.rb', line 163

def does_not_match_all(others, escape = nil)
  grouping_all :does_not_match, others, escape
end

#does_not_match_any(others, escape = nil) ⇒ Object



159
160
161
# File 'activerecord/lib/arel/predications.rb', line 159

def does_not_match_any(others, escape = nil)
  grouping_any :does_not_match, others, escape
end

#does_not_match_regexp(other, case_sensitive = true) ⇒ Object



155
156
157
# File 'activerecord/lib/arel/predications.rb', line 155

def does_not_match_regexp(other, case_sensitive = true)
  Nodes::NotRegexp.new self, quoted_node(other), case_sensitive
end

#eq(other) ⇒ Object



17
18
19
# File 'activerecord/lib/arel/predications.rb', line 17

def eq(other)
  Nodes::Equality.new self, quoted_node(other)
end

#eq_all(others) ⇒ Object



33
34
35
# File 'activerecord/lib/arel/predications.rb', line 33

def eq_all(others)
  grouping_all :eq, quoted_array(others)
end

#eq_any(others) ⇒ Object



29
30
31
# File 'activerecord/lib/arel/predications.rb', line 29

def eq_any(others)
  grouping_any :eq, others
end

#gt(right) ⇒ Object



179
180
181
# File 'activerecord/lib/arel/predications.rb', line 179

def gt(right)
  Nodes::GreaterThan.new self, quoted_node(right)
end

#gt_all(others) ⇒ Object



187
188
189
# File 'activerecord/lib/arel/predications.rb', line 187

def gt_all(others)
  grouping_all :gt, others
end

#gt_any(others) ⇒ Object



183
184
185
# File 'activerecord/lib/arel/predications.rb', line 183

def gt_any(others)
  grouping_any :gt, others
end

#gteq(right) ⇒ Object



167
168
169
# File 'activerecord/lib/arel/predications.rb', line 167

def gteq(right)
  Nodes::GreaterThanOrEqual.new self, quoted_node(right)
end

#gteq_all(others) ⇒ Object



175
176
177
# File 'activerecord/lib/arel/predications.rb', line 175

def gteq_all(others)
  grouping_all :gteq, others
end

#gteq_any(others) ⇒ Object



171
172
173
# File 'activerecord/lib/arel/predications.rb', line 171

def gteq_any(others)
  grouping_any :gteq, others
end

#in(other) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'activerecord/lib/arel/predications.rb', line 59

def in(other)
  case other
  when Arel::SelectManager
    Arel::Nodes::In.new(self, other.ast)
  when Range
    if $VERBOSE
      warn <<-eowarn
Passing a range to `#in` is deprecated. Call `#between`, instead.
      eowarn
    end
    between(other)
  when Enumerable
    Nodes::In.new self, quoted_array(other)
  else
    Nodes::In.new self, quoted_node(other)
  end
end

#in_all(others) ⇒ Object



81
82
83
# File 'activerecord/lib/arel/predications.rb', line 81

def in_all(others)
  grouping_all :in, others
end

#in_any(others) ⇒ Object



77
78
79
# File 'activerecord/lib/arel/predications.rb', line 77

def in_any(others)
  grouping_any :in, others
end

#is_distinct_from(other) ⇒ Object



25
26
27
# File 'activerecord/lib/arel/predications.rb', line 25

def is_distinct_from(other)
  Nodes::IsDistinctFrom.new self, quoted_node(other)
end

#is_not_distinct_from(other) ⇒ Object



21
22
23
# File 'activerecord/lib/arel/predications.rb', line 21

def is_not_distinct_from(other)
  Nodes::IsNotDistinctFrom.new self, quoted_node(other)
end

#lt(right) ⇒ Object



191
192
193
# File 'activerecord/lib/arel/predications.rb', line 191

def lt(right)
  Nodes::LessThan.new self, quoted_node(right)
end

#lt_all(others) ⇒ Object



199
200
201
# File 'activerecord/lib/arel/predications.rb', line 199

def lt_all(others)
  grouping_all :lt, others
end

#lt_any(others) ⇒ Object



195
196
197
# File 'activerecord/lib/arel/predications.rb', line 195

def lt_any(others)
  grouping_any :lt, others
end

#lteq(right) ⇒ Object



203
204
205
# File 'activerecord/lib/arel/predications.rb', line 203

def lteq(right)
  Nodes::LessThanOrEqual.new self, quoted_node(right)
end

#lteq_all(others) ⇒ Object



211
212
213
# File 'activerecord/lib/arel/predications.rb', line 211

def lteq_all(others)
  grouping_all :lteq, others
end

#lteq_any(others) ⇒ Object



207
208
209
# File 'activerecord/lib/arel/predications.rb', line 207

def lteq_any(others)
  grouping_any :lteq, others
end

#matches(other, escape = nil, case_sensitive = false) ⇒ Object



135
136
137
# File 'activerecord/lib/arel/predications.rb', line 135

def matches(other, escape = nil, case_sensitive = false)
  Nodes::Matches.new self, quoted_node(other), escape, case_sensitive
end

#matches_all(others, escape = nil, case_sensitive = false) ⇒ Object



147
148
149
# File 'activerecord/lib/arel/predications.rb', line 147

def matches_all(others, escape = nil, case_sensitive = false)
  grouping_all :matches, others, escape, case_sensitive
end

#matches_any(others, escape = nil, case_sensitive = false) ⇒ Object



143
144
145
# File 'activerecord/lib/arel/predications.rb', line 143

def matches_any(others, escape = nil, case_sensitive = false)
  grouping_any :matches, others, escape, case_sensitive
end

#matches_regexp(other, case_sensitive = true) ⇒ Object



139
140
141
# File 'activerecord/lib/arel/predications.rb', line 139

def matches_regexp(other, case_sensitive = true)
  Nodes::Regexp.new self, quoted_node(other), case_sensitive
end

#not_between(other) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'activerecord/lib/arel/predications.rb', line 85

def not_between(other)
  if unboundable?(other.begin) == 1 || unboundable?(other.end) == -1
    not_in([])
  elsif other.begin.nil? || open_ended?(other.begin)
    if other.end.nil? || open_ended?(other.end)
      self.in([])
    elsif other.exclude_end?
      gteq(other.end)
    else
      gt(other.end)
    end
  elsif other.end.nil? || open_ended?(other.end)
    lt(other.begin)
  else
    left = lt(other.begin)
    right = if other.exclude_end?
      gteq(other.end)
    else
      gt(other.end)
    end
    left.or(right)
  end
end

#not_eq(other) ⇒ Object



5
6
7
# File 'activerecord/lib/arel/predications.rb', line 5

def not_eq(other)
  Nodes::NotEqual.new self, quoted_node(other)
end

#not_eq_all(others) ⇒ Object



13
14
15
# File 'activerecord/lib/arel/predications.rb', line 13

def not_eq_all(others)
  grouping_all :not_eq, others
end

#not_eq_any(others) ⇒ Object



9
10
11
# File 'activerecord/lib/arel/predications.rb', line 9

def not_eq_any(others)
  grouping_any :not_eq, others
end

#not_in(other) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'activerecord/lib/arel/predications.rb', line 109

def not_in(other)
  case other
  when Arel::SelectManager
    Arel::Nodes::NotIn.new(self, other.ast)
  when Range
    if $VERBOSE
      warn <<-eowarn
Passing a range to `#not_in` is deprecated. Call `#not_between`, instead.
      eowarn
    end
    not_between(other)
  when Enumerable
    Nodes::NotIn.new self, quoted_array(other)
  else
    Nodes::NotIn.new self, quoted_node(other)
  end
end

#not_in_all(others) ⇒ Object



131
132
133
# File 'activerecord/lib/arel/predications.rb', line 131

def not_in_all(others)
  grouping_all :not_in, others
end

#not_in_any(others) ⇒ Object



127
128
129
# File 'activerecord/lib/arel/predications.rb', line 127

def not_in_any(others)
  grouping_any :not_in, others
end

#when(right) ⇒ Object



215
216
217
# File 'activerecord/lib/arel/predications.rb', line 215

def when(right)
  Nodes::Case.new(self).when quoted_node(right)
end