Module: ActiveRecord::Refined::AST::Predications
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
- #!=(other) ⇒ Object
- #!~(pattern) ⇒ Object
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
-
#==(other) ⇒ Object
and != mean SQL = and <>, and = NULL is never true there, so nil is rejected rather than silently rewritten to IS NULL.
- #=~(pattern) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
- #between?(min, max) ⇒ Boolean
- #end_with?(*suffixes) ⇒ Boolean
- #in?(values) ⇒ Boolean
- #include?(substring) ⇒ Boolean
- #like?(pattern) ⇒ Boolean
- #member?(element) ⇒ Boolean
- #null? ⇒ Boolean
- #start_with?(*prefixes) ⇒ Boolean
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
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
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
53 54 55 |
# File 'lib/active_record/refined/ast.rb', line 53 def in?(values) In.new(self, values) end |
#include?(substring) ⇒ 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
61 62 63 |
# File 'lib/active_record/refined/ast.rb', line 61 def like?(pattern) Like.new(self, pattern) end |
#member?(element) ⇒ Boolean
83 84 85 |
# File 'lib/active_record/refined/ast.rb', line 83 def member?(element) Member.new(self, element) end |
#null? ⇒ Boolean
49 50 51 |
# File 'lib/active_record/refined/ast.rb', line 49 def null? Comparison.new(self, :==, nil) end |