Module: ActiveRecord::Refined::AST::Predications

Included in:
Aggregate, Column, Function
Defined in:
lib/active_record/refined/ast.rb

Overview

Predicate builders shared by symbols, qualified columns and expressions. Imported into the Symbol refinement with Refinement#import_methods, so every method must be defined with def.

Instance Method Summary collapse

Instance Method Details

#!=(other) ⇒ Object



18
19
20
21
22
23
# File 'lib/active_record/refined/ast.rb', line 18

def !=(other)
  if other.nil?
    raise ArgumentError, "!= does not take nil; use !null? instead"
  end
  Comparison.new(self, :!=, other)
end

#!~(pattern) ⇒ Object



45
46
47
# File 'lib/active_record/refined/ast.rb', line 45

def !~(pattern)
  Match.new(self, pattern, negated: true)
end

#<(other) ⇒ Object



33
34
35
# File 'lib/active_record/refined/ast.rb', line 33

def <(other)
  Comparison.new(self, :<, other)
end

#<=(other) ⇒ Object



37
38
39
# File 'lib/active_record/refined/ast.rb', line 37

def <=(other)
  Comparison.new(self, :<=, other)
end

#==(other) ⇒ Object

and != mean SQL = and <>, and = NULL is never true there, so nil

is rejected rather than silently rewritten to IS NULL. null? builds its node directly and stays clear of this check.



11
12
13
14
15
16
# File 'lib/active_record/refined/ast.rb', line 11

def ==(other)
  if other.nil?
    raise ArgumentError, "== does not take nil; use null? instead"
  end
  Comparison.new(self, :==, other)
end

#=~(pattern) ⇒ Object



41
42
43
# File 'lib/active_record/refined/ast.rb', line 41

def =~(pattern)
  Match.new(self, pattern)
end

#>(other) ⇒ Object



25
26
27
# File 'lib/active_record/refined/ast.rb', line 25

def >(other)
  Comparison.new(self, :>, other)
end

#>=(other) ⇒ Object



29
30
31
# File 'lib/active_record/refined/ast.rb', line 29

def >=(other)
  Comparison.new(self, :>=, other)
end

#between?(min, max) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/active_record/refined/ast.rb', line 57

def between?(min, max)
  In.new(self, min..max)
end

#end_with?(*suffixes) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
76
77
# File 'lib/active_record/refined/ast.rb', line 72

def end_with?(*suffixes)
  if suffixes.empty?
    raise ArgumentError, "end_with? needs at least one suffix"
  end
  Like.any(self, suffixes.map {|suffix| "%#{Like.escape(suffix)}" })
end

#in?(values) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/active_record/refined/ast.rb', line 53

def in?(values)
  In.new(self, values)
end

#include?(substring) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/active_record/refined/ast.rb', line 79

def include?(substring)
  Like.new(self, "%#{Like.escape(substring)}%", Like::ESCAPE)
end

#like?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/active_record/refined/ast.rb', line 61

def like?(pattern)
  Like.new(self, pattern)
end

#member?(element) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/active_record/refined/ast.rb', line 83

def member?(element)
  Member.new(self, element)
end

#null?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/active_record/refined/ast.rb', line 49

def null?
  Comparison.new(self, :==, nil)
end

#start_with?(*prefixes) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
# File 'lib/active_record/refined/ast.rb', line 65

def start_with?(*prefixes)
  if prefixes.empty?
    raise ArgumentError, "start_with? needs at least one prefix"
  end
  Like.any(self, prefixes.map {|prefix| "#{Like.escape(prefix)}%" })
end