paged_groups 2.0.0 → 2.1.0

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
2
  SHA256:
3
- metadata.gz: 1eda61f9a3bdd341677d3af689ecb14815ec276f83bfe771a7da256d8ac22a97
4
- data.tar.gz: 6cd7fe9d4ac34e185bf52fdd1b5fdd4ca752585900f2bfa7b11241122e2e80b6
3
+ metadata.gz: 231bf208ec9d23371baf0e22c950c4ad3fbc5c5eb1b60ea33ab9fed182755306
4
+ data.tar.gz: 476453f30988a874ee876fa8578556df085785834a1f500a0bcbf6b52b1c6254
5
5
  SHA512:
6
- metadata.gz: 8f39ca31c34c31ae6afc77772749c385e99a9660c04f3052736b64367b69424dc7e89d58dfc24c888c1bbc8a776bd4deab3249aaf5eb7869eaa9b41fe4440a75
7
- data.tar.gz: 3401fa08caffcac8e17b555436e1275b1a982a1484104ed8c7608666c813890f826d197e77110eb83c94bde84cf7b3a8f3686ac5483a13aa2e7d3dd2721d04df
6
+ metadata.gz: ad4d0e9d3e50af974373cc3b036ca32aaf75921328d07bf776c30a45dbd30a8c96cab243e1a0983153a76df3de4b1f77f41c33aaa6a76f59187f4ffcd206dffa
7
+ data.tar.gz: 5038f106275131795215f4648fdcebdc7d3c33ef4eafdffde8bdd0dfdb69eef4f4c6b73729db7fd9360eb60965d7b1dbda2d96c56965850eb45da04614455742
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  .DS_Store
2
2
  *.gem
3
3
  /tmp
4
+ /coverage
@@ -1,11 +1,20 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=4f0bd2df4452665b4d6235501f7d663d730395d84b3ca09c55573ba79e9f8e82
1
4
  language: ruby
2
5
  rvm:
3
- # Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
4
- - 2.3.8
5
- - 2.4.5
6
- - 2.5.3
7
- - 2.6.0
6
+ # Build on the latest stable of all supported Rubies (https://www.ruby-lang.org/en/downloads/):
7
+ - 2.3.8
8
+ - 2.4.5
9
+ - 2.5.3
10
+ - 2.6.0
8
11
  cache: bundler
12
+ before_script:
13
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14
+ - chmod +x ./cc-test-reporter
15
+ - ./cc-test-reporter before-build
9
16
  script:
10
- - bundle exec rubocop
11
- - bundle exec rspec
17
+ - bundle exec rubocop
18
+ - bundle exec rspec
19
+ after_script:
20
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -1,3 +1,7 @@
1
+ # 2.1.0 (February 14th, 2019)
2
+
3
+ * Added limit option for builder. This (optionally) ensures no group can exceed a given threshold.
4
+
1
5
  # 2.0.0 (January 29th, 2019)
2
6
 
3
7
  * Breaking Change: Builder#add signature changed from groups splat operator to two-dimensional array. Splat operator introduces an under-the-hood copy and can impact performance with large argument lists.
@@ -1,14 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paged_groups (2.0.0)
4
+ paged_groups (2.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
+ ansi (1.5.0)
9
10
  ast (2.4.0)
10
11
  coderay (1.1.2)
11
12
  diff-lcs (1.3)
13
+ docile (1.3.1)
12
14
  ffi (1.9.25)
13
15
  formatador (0.2.5)
14
16
  guard (2.15.0)
@@ -25,7 +27,9 @@ GEM
25
27
  guard (~> 2.1)
26
28
  guard-compat (~> 1.1)
27
29
  rspec (>= 2.99.0, < 4.0)
28
- jaro_winkler (1.5.1)
30
+ hirb (0.7.3)
31
+ jaro_winkler (1.5.2)
32
+ json (2.1.0)
29
33
  listen (3.1.5)
30
34
  rb-fsevent (~> 0.9, >= 0.9.4)
31
35
  rb-inotify (~> 0.9, >= 0.9.7)
@@ -36,8 +40,8 @@ GEM
36
40
  notiffany (0.1.1)
37
41
  nenv (~> 0.1)
38
42
  shellany (~> 0.0)
39
- parallel (1.12.1)
40
- parser (2.5.3.0)
43
+ parallel (1.13.0)
44
+ parser (2.6.0.0)
41
45
  ast (~> 2.4.0)
42
46
  powerpack (0.1.2)
43
47
  pry (0.12.2)
@@ -60,19 +64,28 @@ GEM
60
64
  diff-lcs (>= 1.2.0, < 2.0)
61
65
  rspec-support (~> 3.8.0)
62
66
  rspec-support (3.8.0)
63
- rubocop (0.59.2)
67
+ rubocop (0.63.1)
64
68
  jaro_winkler (~> 1.5.1)
65
69
  parallel (~> 1.10)
66
70
  parser (>= 2.5, != 2.5.1.1)
67
71
  powerpack (~> 0.1)
68
72
  rainbow (>= 2.2.2, < 4.0)
69
73
  ruby-progressbar (~> 1.7)
70
- unicode-display_width (~> 1.0, >= 1.0.1)
74
+ unicode-display_width (~> 1.4.0)
71
75
  ruby-progressbar (1.10.0)
72
76
  ruby_dep (1.5.0)
73
77
  shellany (0.0.1)
78
+ simplecov (0.16.1)
79
+ docile (~> 1.1)
80
+ json (>= 1.8, < 3)
81
+ simplecov-html (~> 0.10.0)
82
+ simplecov-console (0.4.2)
83
+ ansi
84
+ hirb
85
+ simplecov
86
+ simplecov-html (0.10.2)
74
87
  thor (0.20.3)
75
- unicode-display_width (1.4.0)
88
+ unicode-display_width (1.4.1)
76
89
 
77
90
  PLATFORMS
78
91
  ruby
@@ -81,7 +94,9 @@ DEPENDENCIES
81
94
  guard-rspec (~> 4.7)
82
95
  paged_groups!
83
96
  rspec (~> 3.8)
84
- rubocop (~> 0.59)
97
+ rubocop (~> 0.63.1)
98
+ simplecov (~> 0.16.1)
99
+ simplecov-console (~> 0.4.2)
85
100
 
86
101
  BUNDLED WITH
87
102
  1.17.3
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # paged_groups
2
2
 
3
- [![Build Status](https://travis-ci.org/bluemarblepayroll/paged_groups.svg?branch=master)](https://travis-ci.org/bluemarblepayroll/paged_groups)
3
+ [![Gem Version](https://badge.fury.io/rb/paged_groups.svg)](https://badge.fury.io/rb/paged_groups) [![Build Status](https://travis-ci.org/bluemarblepayroll/paged_groups.svg?branch=master)](https://travis-ci.org/bluemarblepayroll/paged_groups) [![Maintainability](https://api.codeclimate.com/v1/badges/905e58c55e1ec9c61383/maintainability)](https://codeclimate.com/github/bluemarblepayroll/paged_groups/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/905e58c55e1ec9c61383/test_coverage)](https://codeclimate.com/github/bluemarblepayroll/paged_groups/test_coverage) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
4
 
5
5
  Imagine a two-dimensional data set (first dimension being group and second dimension being record) for which you wanted to page with the following rules:
6
6
 
@@ -139,7 +139,6 @@ Now, our resulting pages would become:
139
139
  ]
140
140
  ````
141
141
 
142
-
143
142
  ### Forcing Same Page
144
143
 
145
144
  Another customization that may come in handy is the ability to force-add groups to the current page. For example, say we wanted to add another group to our initial data set, but we want it to end up on the same page as the last records:
@@ -192,6 +191,16 @@ Now the result pages would be:
192
191
  ]
193
192
  ````
194
193
 
194
+ #### Group Size Upper Bound
195
+
196
+ You may run into the case where a group is just so large that it makes more sense to just split it up than keep it atomic. In this case, you can specify a 'limit' option:
197
+
198
+ ````ruby
199
+ pages = PagedGroups.builder(page_size: 50, limit: 150).add(data).all
200
+ ````
201
+
202
+ The above builder can now be interpreted as: *Each page should contain a maximum of 50 rows, but split groups over 150 rows*
203
+
195
204
  ## Contributing
196
205
 
197
206
  ### Development Environment Configuration
@@ -14,11 +14,13 @@ module PagedGroups
14
14
 
15
15
  attr_reader :page_size,
16
16
  :page_count,
17
+ :limit,
17
18
  :row_count,
18
19
  :space,
19
20
  :spacer
20
21
 
21
- def initialize(page_size: DEFAULT_PAGE_SIZE, space: false, spacer: nil)
22
+ def initialize(limit: nil, page_size: DEFAULT_PAGE_SIZE, space: false, spacer: nil)
23
+ @limit = limit ? limit.to_i : nil
22
24
  @page_size = page_size ? page_size.to_i : DEFAULT_PAGE_SIZE
23
25
  @space = space || false
24
26
  @spacer = spacer
@@ -31,7 +33,11 @@ module PagedGroups
31
33
  def add(groups, force: false)
32
34
  dirty!
33
35
 
34
- groups.each { |group| insert(Array(group), force: force) }
36
+ groups.each do |group|
37
+ limit_group_slice(Array(group)).each do |split_group|
38
+ insert(split_group, force: force)
39
+ end
40
+ end
35
41
 
36
42
  self
37
43
  end
@@ -102,8 +108,12 @@ module PagedGroups
102
108
  not_top? && proposed_current_page_length > page_size
103
109
  end
104
110
 
105
- def end_of_current_page?
106
- @current_page.length >= page_size
111
+ def limit_group_slice(group)
112
+ if limit
113
+ group.each_slice(limit)
114
+ else
115
+ [group]
116
+ end
107
117
  end
108
118
  end
109
119
  end
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module PagedGroups
11
- VERSION = '2.0.0'
11
+ VERSION = '2.1.0'
12
12
  end
@@ -25,5 +25,7 @@ Gem::Specification.new do |s|
25
25
 
26
26
  s.add_development_dependency('guard-rspec', '~>4.7')
27
27
  s.add_development_dependency('rspec', '~> 3.8')
28
- s.add_development_dependency('rubocop', '~> 0.59')
28
+ s.add_development_dependency('rubocop', '~>0.63.1')
29
+ s.add_development_dependency('simplecov', '~>0.16.1')
30
+ s.add_development_dependency('simplecov-console', '~>0.4.2')
29
31
  end
@@ -26,6 +26,18 @@ describe ::PagedGroups::Builder do
26
26
 
27
27
  it { expect(page_builder.page_size).to eq(page_size) }
28
28
 
29
+ describe '#to_s' do
30
+ it 'should return page and row count' do
31
+ class_name = ::PagedGroups::Builder.name
32
+ page_count = subject.page_count
33
+ row_count = subject.row_count
34
+
35
+ expected = "[#{class_name}] Page Count: #{page_count}, Row Count: #{row_count}"
36
+
37
+ expect(subject.to_s).to eq(expected)
38
+ end
39
+ end
40
+
29
41
  describe '#add and #all' do
30
42
  it 'should page groups' do
31
43
  page_builder.add([hundred_rows])
@@ -45,6 +45,36 @@ describe ::PagedGroups do
45
45
 
46
46
  let(:spacer) { { id: nil, name: '' } }
47
47
 
48
+ specify 'Number of records per page should never exceed limit' do
49
+ pages = PagedGroups.builder(page_size: page_size, limit: 4).add(data).all
50
+
51
+ expected_pages = [
52
+ [
53
+ { id: 1, name: 'Jordan' },
54
+ { id: 2, name: 'Pippen' },
55
+ { id: 3, name: 'Rodman' },
56
+ { id: 4, name: 'Harper' }
57
+ ],
58
+ [
59
+ { id: 5, name: 'Longley' },
60
+ { id: 6, name: 'Kukoc' },
61
+ { id: 7, name: 'Kerr' }
62
+ ],
63
+ [
64
+ { id: 8, name: 'Buechler' },
65
+ { id: 9, name: 'Wennington' },
66
+ { id: 10, name: 'Simpkins' }
67
+ ],
68
+ [
69
+ { id: 11, name: 'Caffey' },
70
+ { id: 12, name: 'Edwards' },
71
+ { id: 13, name: 'Salley' }
72
+ ]
73
+ ]
74
+
75
+ expect(pages).to eq(expected_pages)
76
+ end
77
+
48
78
  specify 'Standard use-case example works as advertised' do
49
79
  pages = PagedGroups.builder(page_size: page_size).add(data).all
50
80
 
@@ -7,4 +7,10 @@
7
7
  # LICENSE file in the root directory of this source tree.
8
8
  #
9
9
 
10
+ require 'simplecov'
11
+ require 'simplecov-console'
12
+
13
+ SimpleCov.formatter = SimpleCov::Formatter::Console
14
+ SimpleCov.start
15
+
10
16
  require './lib/paged_groups'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paged_groups
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-29 00:00:00.000000000 Z
11
+ date: 2019-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard-rspec
@@ -44,14 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.59'
47
+ version: 0.63.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.59'
54
+ version: 0.63.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.16.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov-console
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.4.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.4.2
55
83
  description: |2
56
84
  This library helps you page grouped-data when the grouped data can have different sizes.
57
85
  It provides a builder that understands how to split pages in a fashion where each page tries to