Class: Chewy::Query::Nodes::Field
- Inherits:
-
Base
show all
- Defined in:
- lib/chewy/query/nodes/field.rb
Instance Method Summary
collapse
Methods inherited from Base
#eql?, #render
Constructor Details
#initialize(name, *args) ⇒ Field
Returns a new instance of Field.
5
6
7
8
|
# File 'lib/chewy/query/nodes/field.rb', line 5
def initialize(name, *args)
@name = name.to_s
@args = args
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
rubocop:disable Style/MethodMissing
81
82
83
84
85
86
87
88
|
# File 'lib/chewy/query/nodes/field.rb', line 81
def method_missing(method, *args) method = method.to_s
if method =~ /\?\Z/
Nodes::Exists.new [@name, method.gsub(/\?\Z/, '')].join('.')
else
self.class.new [@name, method].join('.'), *args
end
end
|
Instance Method Details
10
11
12
|
# File 'lib/chewy/query/nodes/field.rb', line 10
def !
Nodes::Missing.new @name
end
|
#!=(other) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/chewy/query/nodes/field.rb', line 55
def !=(other)
case other
when nil
Nodes::Exists.new @name
else
Nodes::Not.new self == other
end
end
|
#!~(other) ⇒ Object
73
74
75
|
# File 'lib/chewy/query/nodes/field.rb', line 73
def !~(other)
Not.new(self =~ other)
end
|
23
24
25
|
# File 'lib/chewy/query/nodes/field.rb', line 23
def <(other)
Nodes::Range.new @name, *__options_merge__(lt: other)
end
|
#<=(other) ⇒ Object
31
32
33
|
# File 'lib/chewy/query/nodes/field.rb', line 31
def <=(other)
Nodes::Range.new @name, *__options_merge__(lt: other, right_closed: true)
end
|
#==(other) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/chewy/query/nodes/field.rb', line 35
def ==(other)
case other
when nil
nil?
when ::Regexp
Nodes::Regexp.new @name, other, *@args
when ::Range
Nodes::Range.new @name, *__options_merge__(gt: other.begin, lt: other.end)
else
if other.is_a?(Array) && other.first.is_a?(::Range)
Nodes::Range.new @name, *__options_merge__(
gt: other.first.first, lt: other.first.last,
left_closed: true, right_closed: true
)
else
Nodes::Equal.new @name, other, *@args
end
end
end
|
#=~(other) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/chewy/query/nodes/field.rb', line 64
def =~(other)
case other
when ::Regexp
Nodes::Regexp.new @name, other, *@args
else
Nodes::Prefix.new @name, other, @args.
end
end
|
19
20
21
|
# File 'lib/chewy/query/nodes/field.rb', line 19
def >(other)
Nodes::Range.new @name, *__options_merge__(gt: other)
end
|
#>=(other) ⇒ Object
27
28
29
|
# File 'lib/chewy/query/nodes/field.rb', line 27
def >=(other)
Nodes::Range.new @name, *__options_merge__(gt: other, left_closed: true)
end
|
#nil? ⇒ Boolean
77
78
79
|
# File 'lib/chewy/query/nodes/field.rb', line 77
def nil?
Nodes::Missing.new @name, existence: false, null_value: true
end
|
90
91
92
|
# File 'lib/chewy/query/nodes/field.rb', line 90
def to_ary
nil
end
|
14
15
16
17
|
# File 'lib/chewy/query/nodes/field.rb', line 14
def ~
__options_merge__!(cache: true)
self
end
|