Class: Postgrest::Builders::FilterBuilder
Constant Summary
collapse
- SIMPLE_MATCHERS =
%i[eq neq gt gte lt lte like is ilike fts plfts phfts wfts].freeze
- RANGE_MATCHERS =
%i[sl sr nxr nxl adj].freeze
Instance Attribute Summary
Attributes inherited from BaseBuilder
#http
Instance Method Summary
collapse
Methods inherited from BaseBuilder
before_execute, before_execute_hooks, #call
Constructor Details
Returns a new instance of FilterBuilder.
11
12
13
14
|
# File 'lib/postgrest/builders/filter_builder.rb', line 11
def initialize(http)
super
@inverse_next = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *columns, as: nil) ⇒ Object
53
54
55
56
57
58
|
# File 'lib/postgrest/builders/filter_builder.rb', line 53
def method_missing(method_name, *columns, as: nil)
decoded_query['select'] += as ? ",#{as}:#{method_name}" : ",#{method_name}"
decoded_query['select'] += columns.empty? ? '(*)' : "(#{columns.join(',')})"
self
end
|
Instance Method Details
#decoded_query ⇒ Object
64
65
66
|
# File 'lib/postgrest/builders/filter_builder.rb', line 64
def decoded_query
@decoded_query ||= URI.decode_www_form(query).to_h
end
|
#in(values = []) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/postgrest/builders/filter_builder.rb', line 34
def in(values = [])
transform_params(method_name: __method__, values: values) do |key, value|
[key, "#{method_key(__method__)}.(#{value.join(',')})"]
end
self
end
|
#limit(number = 0) ⇒ Object
68
69
70
71
|
# File 'lib/postgrest/builders/filter_builder.rb', line 68
def limit(number = 0)
decoded_query['limit'] = number
self
end
|
#not ⇒ Object
78
79
80
81
|
# File 'lib/postgrest/builders/filter_builder.rb', line 78
def not
@inverse_next = !@inverse_next
self
end
|
#offset(number = 0) ⇒ Object
73
74
75
76
|
# File 'lib/postgrest/builders/filter_builder.rb', line 73
def offset(number = 0)
decoded_query['offset'] = number
self
end
|
#order(values) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/postgrest/builders/filter_builder.rb', line 42
def order(values)
transform_params(method_name: __method__, values: values) do |key, value|
asc = value.to_sym != :desc
asc = !asc if should_invert?
[__method__, "#{key}.#{asc ? 'asc' : 'desc'}"]
end
self
end
|
#query ⇒ Object
60
61
62
|
# File 'lib/postgrest/builders/filter_builder.rb', line 60
def query
http.uri.query
end
|