mongoid_query_string_interface 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid_query_string_interface (0.6.0)
5
- mongoid (~> 2.0.2)
4
+ mongoid_query_string_interface (0.6.2)
5
+ mongoid (>= 2.0.2)
6
6
  query_string_interface (>= 0.1.0)
7
7
  will_paginate (~> 3.0.pre2)
8
8
 
@@ -5,9 +5,15 @@ module Mongoid
5
5
  page = (options[:page] || 1).to_i
6
6
  offset = (page - 1) * per_page
7
7
 
8
- WillPaginate::Collection.create(page, per_page, count) do |pager|
9
- pager.replace(skip(offset).limit(per_page).to_a)
10
- end
8
+ create_paginatable_collection(skip(offset).limit(per_page).to_a, count, page, per_page)
11
9
  end
10
+
11
+ protected
12
+
13
+ def create_paginatable_collection(collection, total, page, per_page)
14
+ WillPaginate::Collection.create(page, per_page, total) do |pager|
15
+ pager.replace(collection)
16
+ end
17
+ end
12
18
  end
13
19
  end
@@ -18,14 +18,7 @@ module Mongoid
18
18
  end
19
19
 
20
20
  def filter_with_pagination_by(params)
21
- result = filter_by(params)
22
-
23
- pager = PAGER_ATTRIBUTES.inject({}) do |pager, attr|
24
- pager[attr] = result.send(attr)
25
- pager
26
- end
27
-
28
- return { :pager => pager, collection_name_in_pagination_result => result }
21
+ build_results_with_pager_for(filter_by(params))
29
22
  end
30
23
 
31
24
  def filter_with_optimized_pagination_by(params={})
@@ -50,12 +43,9 @@ module Mongoid
50
43
  params = hash_with_indifferent_access(params)
51
44
 
52
45
  pagination = pagination_options(params)
53
- pager = WillPaginate::Collection.new pagination[:page], pagination[:per_page], where(filtering_options(params)).count
46
+ collection = WillPaginate::Collection.new pagination[:page], pagination[:per_page], where(filtering_options(params)).count
54
47
 
55
- PAGER_ATTRIBUTES.inject({}) do |result, attr|
56
- result[attr] = pager.send(attr)
57
- result
58
- end
48
+ build_pager_from(collection)
59
49
  end
60
50
 
61
51
  protected
@@ -66,6 +56,25 @@ module Mongoid
66
56
  end
67
57
  end
68
58
 
59
+ def results_with_pager(collection, total, params={})
60
+ params = hash_with_indifferent_access(params)
61
+ pagination = pagination_options(params)
62
+
63
+ result = create_paginatable_collection(collection, total, pagination[:page], pagination[:per_page])
64
+ build_results_with_pager_for(result)
65
+ end
66
+
67
+ def build_pager_from(collection)
68
+ PAGER_ATTRIBUTES.inject({}) do |result, attr|
69
+ result[attr] = collection.send(attr)
70
+ result
71
+ end
72
+ end
73
+
74
+ def build_results_with_pager_for(collection)
75
+ { :pager => build_pager_from(collection), collection_name_in_pagination_result => collection }
76
+ end
77
+
69
78
  def collection_name_in_pagination_result
70
79
  model_name.human.underscore.pluralize.to_sym
71
80
  end
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
3
  module QueryStringInterface #:nodoc
4
- VERSION = "0.6.1"
4
+ VERSION = "0.6.2"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,82 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mongoid_query_string_interface
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.2
4
5
  prerelease:
5
- version: 0.6.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Vicente Mundim
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-12-07 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-28 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: query_string_interface
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2160890640 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 0.1.0
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: will_paginate
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2160890640
25
+ - !ruby/object:Gem::Dependency
26
+ name: will_paginate
27
+ requirement: &2160890160 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
29
+ requirements:
32
30
  - - ~>
33
- - !ruby/object:Gem::Version
31
+ - !ruby/object:Gem::Version
34
32
  version: 3.0.pre2
35
33
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: mongoid
39
34
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2160890160
36
+ - !ruby/object:Gem::Dependency
37
+ name: mongoid
38
+ requirement: &2160889680 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
45
43
  version: 2.0.2
46
44
  type: :runtime
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: rspec
50
45
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2160889680
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &2160889200 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
56
54
  version: 2.3.0
57
55
  type: :development
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: database_cleaner
61
56
  prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *2160889200
58
+ - !ruby/object:Gem::Dependency
59
+ name: database_cleaner
60
+ requirement: &2160918400 !ruby/object:Gem::Requirement
63
61
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
67
65
  version: 0.5.0
68
66
  type: :development
69
- version_requirements: *id005
70
- description: Gives a method that can parse query string parameters into a set of criterias that Mongoid can use to perform actual queries in MongoDB databases for a given model.
71
- email:
67
+ prerelease: false
68
+ version_requirements: *2160918400
69
+ description: Gives a method that can parse query string parameters into a set of criterias
70
+ that Mongoid can use to perform actual queries in MongoDB databases for a given
71
+ model.
72
+ email:
72
73
  - vicente.mundim@gmail.com
73
74
  executables: []
74
-
75
75
  extensions: []
76
-
77
76
  extra_rdoc_files: []
78
-
79
- files:
77
+ files:
80
78
  - lib/mongoid/paginate.rb
81
79
  - lib/mongoid/query_string_interface.rb
82
80
  - lib/mongoid_query_string_interface.rb
@@ -87,30 +85,26 @@ files:
87
85
  - Gemfile.lock
88
86
  homepage: http://github.com/vicentemundim/mongoid_query_string_interface
89
87
  licenses: []
90
-
91
88
  post_install_message:
92
89
  rdoc_options: []
93
-
94
- require_paths:
90
+ require_paths:
95
91
  - lib
96
- required_ruby_version: !ruby/object:Gem::Requirement
92
+ required_ruby_version: !ruby/object:Gem::Requirement
97
93
  none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- version: "0"
102
- required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
99
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
107
103
  version: 1.3.6
108
104
  requirements: []
109
-
110
105
  rubyforge_project: mongoid_query_string_interface
111
- rubygems_version: 1.8.10
106
+ rubygems_version: 1.8.15
112
107
  signing_key:
113
108
  specification_version: 3
114
109
  summary: An interface for performing queries in MongoDB using query string parameters.
115
110
  test_files: []
116
-