wor-paginate 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: b7c776afdec6b7a3b5d25d291feee578bf5c197ab0504764cd820bad2d7a4ff0
4
- data.tar.gz: 5a8daf10d3c2c4946ba9a3f93b4e471b6d7df4f36fb3dbd7dc012b8aae7ee482
2
+ SHA1:
3
+ metadata.gz: c6a4d0f06558e5204961f4db988546335b5e51b3
4
+ data.tar.gz: b56ec43ef75a22e28c255c9ca0a7f4054a66fbed
5
5
  SHA512:
6
- metadata.gz: 563abfa98659357d211b0a2a82879c4ebfb990d3a1305a1ce45520457fccc40a01fd1337d3454a1e292a3fcdb3250fb0905a9b6558f81685af9ea0ed5db17626
7
- data.tar.gz: c48165f34eaf321463d679fbb252bde74250b789cc82c3789e0d88cfa271f492bb8d6f24b77cbdc812e64ab32695361ab2aa44aa612439646855f724d1805880
6
+ metadata.gz: a75d8db76635df594ad2870088cc12b151c7dc4c65af4029c3dc92a527f6eb370fa2a0744e9a704fc47776d913df6c744128abebecd9f278e555b8810be7c7a7
7
+ data.tar.gz: b40078aee535d5c676afd501b96e9bfbd781c17143dbb7ac3923ea8593f98c5db66be41f8ab7c4e477e7e748a57c6a5ee494c0ac19a8eccad2473b569444d47e
@@ -5,6 +5,7 @@ AllCops:
5
5
  - spec/dummy/db/**/*
6
6
  - spec/dummy/config/**/*
7
7
  - spec/spec_helper.rb
8
+ TargetRubyVersion: 2.3.8
8
9
 
9
10
  Documentation:
10
11
  Enabled: false
@@ -1,5 +1,10 @@
1
1
  ## Change log
2
2
 
3
+ ### V0.1.9
4
+ * [#88](https://github.com/Wolox/wor-paginate/pull/88) Default adapter - [@mtejedorwolox](https://github.com/mtejedorwolox).
5
+ * [#87](https://github.com/Wolox/wor-paginate/pull/87) Supporting expect(response).to be_paginated - [@mnmallea](https://github.com/mnmallea).
6
+ * [#86](https://github.com/Wolox/wor-paginate/pull/86) Added previous_page parameter - [@juanpablo-rojas](https://github.com/juanpablo-rojas).
7
+
3
8
  ### V0.1.8
4
9
  * [#85](https://github.com/Wolox/wor-paginate/pull/85) Delete max Railties dependency in gemspec - [@lucasvoboril](https://github.com/lucasvoboril).
5
10
 
data/README.md CHANGED
@@ -88,6 +88,7 @@ The response to the index will then be:
88
88
  "total_pages": 2,
89
89
  "total_count": 28,
90
90
  "current_page": 1,
91
+ "previous_page": null,
91
92
  "next_page": 2
92
93
  }
93
94
  ```
@@ -10,4 +10,16 @@ Wor::Paginate.configure do |config|
10
10
  # For more info about available methods for formatters see:
11
11
  # https://github.com/Wolox/wor-paginate/blob/master/lib/wor/paginate/formatter.rb
12
12
  # config.formatter = Wor::Paginate::Formatter
13
+
14
+ # Configure a default adapter to use on pagination
15
+ # config.default_adapter = nil
16
+
17
+ # Default: nil
18
+ # Possible values:
19
+ # Wor::Paginate::Adapters::KaminariAlreadyPaginated
20
+ # Wor::Paginate::Adapters::WillPaginateAlreadyPaginated
21
+ # Wor::Paginate::Adapters::WillPaginate
22
+ # Wor::Paginate::Adapters::Kaminari
23
+ # Wor::Paginate::Adapters::ActiveRecord
24
+ # Wor::Paginate::Adapters::Enumerable
13
25
  end
@@ -24,8 +24,15 @@ module Wor
24
24
 
25
25
  def next_page
26
26
  return nil if page >= total_pages
27
+
27
28
  page + 1
28
29
  end
30
+
31
+ def previous_page
32
+ return nil if page == 1
33
+
34
+ page - 1
35
+ end
29
36
  end
30
37
  end
31
38
  end
@@ -4,11 +4,10 @@ module Wor
4
4
  module Helpers
5
5
  module TotalCount
6
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
7
+ @content_size ||= @content.reorder(nil).size
8
+ return @content_size.keys.size if @content_size.is_a? Hash
10
9
 
11
- content_size
10
+ @content_size
12
11
  end
13
12
  end
14
13
  end
@@ -13,6 +13,10 @@ module Wor
13
13
  @paginated_content ||= @content.page(@page).per(@limit)
14
14
  end
15
15
 
16
+ def previous_page
17
+ paginated_content.prev_page
18
+ end
19
+
16
20
  delegate :count, :total_count, :total_pages, :next_page, to: :paginated_content
17
21
  end
18
22
  end
@@ -23,7 +23,7 @@ module Wor
23
23
  paginated_content.to_a.size
24
24
  end
25
25
 
26
- delegate :total_pages, :next_page, to: :paginated_content
26
+ delegate :total_pages, :previous_page, :next_page, to: :paginated_content
27
27
  end
28
28
  end
29
29
  end
@@ -7,7 +7,8 @@ module Wor
7
7
  page_param: :page,
8
8
  per_page_param: :limit,
9
9
  formatter: Wor::Paginate::Formatter,
10
- max_limit: 50
10
+ max_limit: 50,
11
+ default_adapter: nil
11
12
  }.freeze
12
13
 
13
14
  module_function
@@ -15,13 +15,14 @@ module Wor
15
15
  total_pages: total_pages,
16
16
  total_count: total_count,
17
17
  current_page: current_page,
18
+ previous_page: previous_page,
18
19
  next_page: next_page
19
20
  }
20
21
  end
21
22
 
22
23
  protected
23
24
 
24
- delegate :count, :total_count, :total_pages, :next_page, to: :adapter
25
+ delegate :count, :total_count, :total_pages, :previous_page, :next_page, to: :adapter
25
26
 
26
27
  def current_page
27
28
  adapter.page.to_i
@@ -32,8 +32,9 @@ module Wor
32
32
  end
33
33
 
34
34
  def find_adapter_for_content(content, options)
35
- ADAPTERS.map { |adapter| adapter.new(content, page(options), limit(options)) }
36
- .find(&:adapt?)
35
+ Config.default_adapter&.new(content, page(options), limit(options)) ||
36
+ ADAPTERS.map { |adapter| adapter.new(content, page(options), limit(options)) }
37
+ .find(&:adapt?)
37
38
  end
38
39
 
39
40
  def page(options)
@@ -28,9 +28,14 @@ end
28
28
 
29
29
  RSpec::Matchers.define :be_paginated do
30
30
  match do |actual_response|
31
+ response = parse_response(actual_response)
31
32
  formatter = @custom_formatter || Wor::Paginate::Formatter
32
33
  @formatted_keys = formatter.new(MockedAdapter.new).format.as_json.keys
33
- actual_response.keys == @formatted_keys
34
+ response.keys == @formatted_keys
35
+ end
36
+
37
+ def parse_response(response)
38
+ response.is_a?(Hash) ? response : JSON.parse(response.body)
34
39
  end
35
40
 
36
41
  chain :with do |custom_formatter|
@@ -38,10 +43,11 @@ RSpec::Matchers.define :be_paginated do
38
43
  end
39
44
 
40
45
  failure_message do |actual_response|
41
- "expected that #{actual_response} to be paginated with keys #{@formatted_keys}"
46
+ "expected that #{parse_response(actual_response)} to be paginated with keys #{@formatted_keys}"
42
47
  end
43
48
 
44
49
  failure_message_when_negated do |actual_response|
45
- "expected that #{actual_response} not to be paginated with keys #{@formatted_keys}"
50
+ "expected that #{parse_response(actual_response)} not " \
51
+ "to be paginated with keys #{@formatted_keys}"
46
52
  end
47
53
  end
@@ -1,5 +1,5 @@
1
1
  module Wor
2
2
  module Paginate
3
- VERSION = '0.1.8'.freeze
3
+ VERSION = '0.1.9'.freeze
4
4
  end
5
5
  end
File without changes
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.8
4
+ version: 0.1.9
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-11-12 00:00:00.000000000 Z
14
+ date: 2019-11-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: railties
@@ -82,6 +82,7 @@ files:
82
82
  - lib/wor/paginate/rspec.rb
83
83
  - lib/wor/paginate/version.rb
84
84
  - pull_request_template.md
85
+ - test.sqlite3
85
86
  - wor-paginate.gemspec
86
87
  homepage: https://github.com/Wolox/wor-paginate
87
88
  licenses:
@@ -102,7 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
103
  - !ruby/object:Gem::Version
103
104
  version: '0'
104
105
  requirements: []
105
- rubygems_version: 3.0.4
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.2.1
106
108
  signing_key:
107
109
  specification_version: 4
108
110
  summary: Simplified pagination for Rails API controllers