Module: Arel::Predications

Included in:
Attributes::Attribute, Nodes::InfixOperation, Nodes::NodeExpression, Nodes::SqlLiteral
Defined in:
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
58
59
60
61
62
63
# File 'lib/arel/predications.rb', line 37

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

#concat(other) ⇒ Object



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

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

#contains(other) ⇒ Object



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

def contains(other)
  Arel::Nodes::Contains.new self, quoted_node(other)
end

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



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

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



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

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

#does_not_match_any(others, escape = nil) ⇒ Object



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

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



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

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 '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 '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 'lib/arel/predications.rb', line 29

def eq_any(others)
  grouping_any :eq, others
end

#gt(right) ⇒ Object



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

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

#gt_all(others) ⇒ Object



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

def gt_all(others)
  grouping_all :gt, others
end

#gt_any(others) ⇒ Object



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

def gt_any(others)
  grouping_any :gt, others
end

#gteq(right) ⇒ Object



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

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

#gteq_all(others) ⇒ Object



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

def gteq_all(others)
  grouping_all :gteq, others
end

#gteq_any(others) ⇒ Object



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

def gteq_any(others)
  grouping_any :gteq, others
end

#in(other) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/arel/predications.rb', line 65

def in(other)
  case other
  when Arel::SelectManager
    Arel::Nodes::In.new(self, other.ast)
  when Enumerable
    Nodes::In.new self, quoted_array(other)
  else
    Nodes::In.new self, quoted_node(other)
  end
end

#in_all(others) ⇒ Object



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

def in_all(others)
  grouping_all :in, others
end

#in_any(others) ⇒ Object



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

def in_any(others)
  grouping_any :in, others
end

#is_distinct_from(other) ⇒ Object



25
26
27
# File '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 'lib/arel/predications.rb', line 21

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

#lt(right) ⇒ Object



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

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

#lt_all(others) ⇒ Object



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

def lt_all(others)
  grouping_all :lt, others
end

#lt_any(others) ⇒ Object



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

def lt_any(others)
  grouping_any :lt, others
end

#lteq(right) ⇒ Object



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

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

#lteq_all(others) ⇒ Object



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

def lteq_all(others)
  grouping_all :lteq, others
end

#lteq_any(others) ⇒ Object



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

def lteq_any(others)
  grouping_any :lteq, others
end

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



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

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



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

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



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

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

#matches_regexp(other, case_sensitive = true) ⇒ Object



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

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

#not_between(other) ⇒ Object



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

def not_between(other)
  if unboundable?(other.begin) == 1 || unboundable?(other.end) == -1
    not_in([])
  elsif open_ended?(other.begin)
    if open_ended?(other.end)
      if infinity?(other.begin) == 1 || infinity?(other.end) == -1
        not_in([])
      else
        self.in([])
      end
    elsif other.exclude_end?
      gteq(other.end)
    else
      gt(other.end)
    end
  elsif 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 '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 '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 'lib/arel/predications.rb', line 9

def not_eq_any(others)
  grouping_any :not_eq, others
end

#not_in(other) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# File 'lib/arel/predications.rb', line 112

def not_in(other)
  case other
  when Arel::SelectManager
    Arel::Nodes::NotIn.new(self, other.ast)
  when Enumerable
    Nodes::NotIn.new self, quoted_array(other)
  else
    Nodes::NotIn.new self, quoted_node(other)
  end
end

#not_in_all(others) ⇒ Object



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

def not_in_all(others)
  grouping_all :not_in, others
end

#not_in_any(others) ⇒ Object



123
124
125
# File 'lib/arel/predications.rb', line 123

def not_in_any(others)
  grouping_any :not_in, others
end

#overlaps(other) ⇒ Object



223
224
225
# File 'lib/arel/predications.rb', line 223

def overlaps(other)
  Arel::Nodes::Overlaps.new self, quoted_node(other)
end

#quoted_array(others) ⇒ Object



227
228
229
# File 'lib/arel/predications.rb', line 227

def quoted_array(others)
  others.map { |v| quoted_node(v) }
end

#when(right) ⇒ Object



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

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