Module: Mongoid::QueryStringInterface
- Includes:
- QueryStringInterface, QueryStringInterface::Helpers
- Defined in:
- lib/version.rb,
lib/mongoid/helpers.rb,
lib/mongoid/parsers/array_parser.rb,
lib/mongoid/parsers/regex_parser.rb,
lib/mongoid/parsers/filter_parser.rb,
lib/mongoid/parsers/number_parser.rb,
lib/mongoid/parsers/filters_parser.rb,
lib/mongoid/query_string_interface.rb,
lib/mongoid/parsers/date_time_parser.rb,
lib/mongoid/parsers/boolean_and_nil_parser.rb
Overview
Defined Under Namespace
Modules: Helpers, Parsers
Constant Summary
collapse
- VERSION =
"0.7.2"
[:total_entries, :total_pages, :per_page, :offset, :previous_page, :current_page, :next_page]
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.extended(base) ⇒ Object
9
10
11
|
# File 'lib/mongoid/query_string_interface.rb', line 9
def self.extended(base)
base.extend Mongoid::Paginate unless base.methods.include?(:paginate)
end
|
Instance Method Details
#field_filtering_options(params) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/mongoid/query_string_interface.rb', line 57
def field_filtering_options(params)
hash = super
if hash.present?
hash = hash.dup
hash[:without] = hash.delete(:except)
end
hash
end
|
#filter_by(params = {}) ⇒ Object
15
16
17
18
|
# File 'lib/mongoid/query_string_interface.rb', line 15
def filter_by(params={})
params = hash_with_indifferent_access(params)
filter_only_and_order_by(params).paginate((params))
end
|
#filter_fields_by(params) ⇒ Object
52
53
54
55
|
# File 'lib/mongoid/query_string_interface.rb', line 52
def filter_fields_by(params)
params = field_filtering_options(hash_with_indifferent_access(params))
params.present? ? send(*params.first) : criteria
end
|
#filter_only_and_order_by(params = {}) ⇒ Object
33
34
35
36
|
# File 'lib/mongoid/query_string_interface.rb', line 33
def filter_only_and_order_by(params={})
params = hash_with_indifferent_access(params)
filter_only_by(params).order_by(*sorting_options(params))
end
|
#filter_only_by(params = {}) ⇒ Object
38
39
40
41
|
# File 'lib/mongoid/query_string_interface.rb', line 38
def filter_only_by(params={})
params = hash_with_indifferent_access(params)
where(filtering_options(params)).filter_fields_by(params)
end
|
24
25
26
27
28
29
30
31
|
# File 'lib/mongoid/query_string_interface.rb', line 24
def (params={})
params = hash_with_indifferent_access(params)
per_page = (params[:per_page] || [:per_page]).to_i
page = (params[:page] || [:page]).to_i
skip = per_page * (page - 1)
filter_only_and_order_by(params).skip(skip).limit(per_page)
end
|
20
21
22
|
# File 'lib/mongoid/query_string_interface.rb', line 20
def (params)
(filter_by(params))
end
|
#paginated_collection_with_filter_by(params = {}) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/mongoid/query_string_interface.rb', line 43
def paginated_collection_with_filter_by(params={})
params = hash_with_indifferent_access(params)
= (params)
collection = WillPaginate::Collection.new [:page], [:per_page], where(filtering_options(params)).count
(collection)
end
|