wor-paginate 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: b525d480a4cfe283c91c14c2a8e2ce570b65ded15e2678d76f1e9c0f35143a24
4
- data.tar.gz: 585dfb16534cc0daafe39dbe52d238a8f1142f80bc65085c95acc9f2e506e9d1
2
+ SHA1:
3
+ metadata.gz: 8dd511971868270eef7127d6f538cc172293f668
4
+ data.tar.gz: bf95f5b82639f6ebfc7fcfedf678d282e5156676
5
5
  SHA512:
6
- metadata.gz: da4b6ae0100e232077386f260c4465412d8cf010240a24011cd68308176f1c7082bbef1890c6f893c10a831d3ec56b8d2e005d33ec877d3f1d299d4888e4b053
7
- data.tar.gz: 83e2ded8da3f41efb31765ed6ef29c076ec659e227c4aab579bf02a490f4c4afc6343a8a45fe3e456767195490fcd52f819a1b1e5f59bad85bb35e83693f4622
6
+ metadata.gz: 35e3fab61135534b3503248ea77a5a3ba42e1e98d738acda1fefb88c61ca030e05f18e7d0b617cd5282290cc0ee8e99135d75f38bb9b4e90e314ba111db36e33
7
+ data.tar.gz: d092291dba845fce0f0a21b1a5088124cc19f334fb84d21f6153433853c2ad8823df05ef4d94351047053fdd61de38a95230ceb9b27bda832a3bf09447851c39
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## Change log
2
2
 
3
+ ### V0.1.7
4
+ * [#61](https://github.com/Wolox/wor-paginate/pull/61) Allows requests on offset pages for enumerables - [@mtejedorwolox](https://github.com/mtejedorwolox).
5
+ * [#63](https://github.com/Wolox/wor-paginate/pull/63) Add max_limit with optional parameter - [@blacksam07](https://github.com/blacksam07).
6
+ * [#71](https://github.com/Wolox/wor-paginate/pull/71) Group by fix - [@mnmallea](https://github.com/mnmallea).
7
+ * [#82](https://github.com/Wolox/wor-paginate/pull/71) Rails 6 support - [@mnmallea](https://github.com/mnmallea).
8
+
3
9
  ### V0.1.6
4
10
  * [#62](https://github.com/Wolox/wor-paginate/pull/62): Add options in active model serializer - [@blacksam07](https://github.com/blacksam07).
5
11
 
data/Gemfile CHANGED
@@ -29,7 +29,7 @@ group :development, :test do
29
29
  gem 'rubocop', '~> 0.49.1'
30
30
  gem 'rubocop-rspec', '~> 1.15.0'
31
31
  gem 'simplecov', '~> 0.13.0'
32
- gem 'sqlite3', '~> 1.3.0'
32
+ gem 'sqlite3', '~> 1.4'
33
33
  gem 'webmock', '~> 3.0.0'
34
34
  gem 'will_paginate', '~> 3.1.0'
35
35
  end
data/README.md CHANGED
@@ -12,6 +12,7 @@ Wor::Paginate
12
12
  - [Basic usage](#basic-usage)
13
13
  - [Customizing output](#customizing-output)
14
14
  - [Custom serializers](#custom-serializers)
15
+ - [Custom options](#custom-options)
15
16
  - [Custom formatters](#custom-formatters)
16
17
  - [Working with Kaminari or will_paginate](#working-with-kaminari-or-will_paginate)
17
18
  - [Test helpers](#test-helpers)
@@ -105,11 +106,22 @@ render_paginated DummyModel, each_serializer: CustomDummyModelSerializer
105
106
  where the serializer is just an [`ActiveModel::Serializer`](https://github.com/rails-api/active_model_serializers).
106
107
 
107
108
  #### Custom options
109
+ ##### max_limit
110
+ The max amount of items is passed through the `max_limit` option, You can set the value in the initializer or in the `render_paginated` method, (If none is supplied, take the default value configured in the initializer). Default is 50.
111
+
112
+ ```ruby
113
+ render_paginated DummyModel, max_limit: 100
114
+ ```
115
+
116
+ ##### current_user
108
117
  Using custom options in serializer, example method `current_user`
118
+
109
119
  ```ruby
110
120
  render_paginated DummyModel, each_serializer: CustomDummyModelSerializer, current_user: current_user
111
121
  ```
122
+
112
123
  In serializer
124
+
113
125
  ```ruby
114
126
  class CustomSerializer < ActiveModel::Serializer
115
127
  def method
@@ -1,3 +1,5 @@
1
+ require_relative 'helpers/total_count'
2
+
1
3
  # Used when render_paginated is called with an ActiveRecord directly, without a
2
4
  # pagination gem like kaminari or will_paginate
3
5
  ### render_paginated DummyModel
@@ -5,6 +7,8 @@ module Wor
5
7
  module Paginate
6
8
  module Adapters
7
9
  class ActiveRecord < Base
10
+ include Helpers::TotalCount
11
+
8
12
  attr_reader :page
9
13
 
10
14
  def required_methods
@@ -15,10 +19,8 @@ module Wor
15
19
  @paginated_content ||= @content.offset(offset).limit(@limit)
16
20
  end
17
21
 
18
- delegate :count, to: :paginated_content
19
-
20
- def total_count
21
- @content.count
22
+ def count
23
+ paginated_content.size
22
24
  end
23
25
 
24
26
  def total_pages
@@ -13,7 +13,7 @@ module Wor
13
13
  def paginated_content
14
14
  return @paginated_content if @paginated_content
15
15
  content_array = @content.to_a
16
- @paginated_content = content_array.slice((page - 1) * @limit, @limit)
16
+ @paginated_content = content_array.slice((page - 1) * @limit, @limit) || []
17
17
  end
18
18
 
19
19
  delegate :count, to: :paginated_content
@@ -0,0 +1,17 @@
1
+ module Wor
2
+ module Paginate
3
+ module Adapters
4
+ module Helpers
5
+ module TotalCount
6
+ def total_count
7
+ content = @content.reorder(nil)
8
+ content_size = content.size
9
+ return content.to_a.size if content_size.is_a? Hash
10
+
11
+ content_size
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ require_relative 'helpers/total_count'
2
+
1
3
  # Used when render_paginated is called with an ActiveModel directly, with will_paginate
2
4
  # already required. Something like
3
5
  ### render_paginated DummyModel
@@ -5,6 +7,8 @@ module Wor
5
7
  module Paginate
6
8
  module Adapters
7
9
  class WillPaginate < Base
10
+ include Helpers::TotalCount
11
+
8
12
  attr_reader :page
9
13
 
10
14
  def required_methods
@@ -19,10 +23,6 @@ module Wor
19
23
  paginated_content.to_a.size
20
24
  end
21
25
 
22
- def total_count
23
- paginated_content.count
24
- end
25
-
26
26
  delegate :total_pages, :next_page, to: :paginated_content
27
27
  end
28
28
  end
@@ -44,6 +44,10 @@ module Wor
44
44
  options[:limit].to_i unless options[:limit].nil?
45
45
  end
46
46
 
47
+ def option_max_limit(options)
48
+ options[:max_limit].to_i unless options[:max_limit].nil?
49
+ end
50
+
47
51
  def param_limit
48
52
  params[Config.per_page_param].to_i unless params[Config.per_page_param].nil?
49
53
  end
@@ -54,7 +58,7 @@ module Wor
54
58
 
55
59
  def limit(options)
56
60
  [
57
- Config.max_limit,
61
+ option_max_limit(options) || Config.max_limit,
58
62
  option_limit(options) || param_limit || Config.default_per_page
59
63
  ].min
60
64
  end
@@ -1,5 +1,5 @@
1
1
  module Wor
2
2
  module Paginate
3
- VERSION = '0.1.6'.freeze
3
+ VERSION = '0.1.7'.freeze
4
4
  end
5
5
  end
data/wor-paginate.gemspec CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ['lib']
20
20
 
21
21
 
22
- s.add_dependency 'railties', '>= 4.1.0', "< 5.3"
22
+ s.add_dependency 'railties', '>= 4.1.0', "<= 6.0.0"
23
23
  s.add_dependency 'rails', '>= 4.0'
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wor-paginate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - icoluccio
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2019-09-13 00:00:00.000000000 Z
14
+ date: 2019-10-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: railties
@@ -20,9 +20,9 @@ dependencies:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 4.1.0
23
- - - "<"
23
+ - - "<="
24
24
  - !ruby/object:Gem::Version
25
- version: '5.3'
25
+ version: 6.0.0
26
26
  type: :runtime
27
27
  prerelease: false
28
28
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,9 +30,9 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 4.1.0
33
- - - "<"
33
+ - - "<="
34
34
  - !ruby/object:Gem::Version
35
- version: '5.3'
35
+ version: 6.0.0
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
38
  requirement: !ruby/object:Gem::Requirement
@@ -74,6 +74,7 @@ files:
74
74
  - lib/wor/paginate/adapters/active_record.rb
75
75
  - lib/wor/paginate/adapters/base.rb
76
76
  - lib/wor/paginate/adapters/enumerable.rb
77
+ - lib/wor/paginate/adapters/helpers/total_count.rb
77
78
  - lib/wor/paginate/adapters/kaminari.rb
78
79
  - lib/wor/paginate/adapters/kaminari_already_paginated.rb
79
80
  - lib/wor/paginate/adapters/will_paginate.rb
@@ -107,7 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  - !ruby/object:Gem::Version
108
109
  version: '0'
109
110
  requirements: []
110
- rubygems_version: 3.0.2
111
+ rubyforge_project:
112
+ rubygems_version: 2.5.2.1
111
113
  signing_key:
112
114
  specification_version: 4
113
115
  summary: Simplified pagination for Rails API controllers