rocket_pants-pagination 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +63 -0
- data/.travis.yml +9 -3
- data/README.md +4 -4
- data/lib/rocket_pants/pagination.rb +13 -35
- data/lib/rocket_pants/pagination/version.rb +2 -1
- data/rocket_pants-pagination.gemspec +7 -5
- metadata +46 -18
- data/lib/rocket_pants/pagination/swagger_schema.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f8806b92d0f6200a0b6c64f4b1a8b70f3118fa6
|
4
|
+
data.tar.gz: 639d41f97e99b961590039c35eb086c0316794f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdbc4c91fede1cb1410109686e36a830b17640d2ea659bb294fa0867e42c872c6d2f9f72e19182385ed27afc8348bd85669ddf87acc69edfa56fe5177134bfab
|
7
|
+
data.tar.gz: 1cdd3e3cf10d49ec01258e876536e9032a55c095b1a1a23485198fdd5d182aea627fea58350df2c95a18a1345f76c9bfb90e738f7c296c84b807325f55dfa655
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.3
|
5
|
+
Include:
|
6
|
+
- '**/Gemfile'
|
7
|
+
- '**/Rakefile'
|
8
|
+
Exclude:
|
9
|
+
- 'bin/*'
|
10
|
+
- 'db/**/*'
|
11
|
+
- 'vendor/bundle/**/*'
|
12
|
+
- 'spec/spec_helper.rb'
|
13
|
+
- 'spec/rails_helper.rb'
|
14
|
+
- 'spec/support/**/*'
|
15
|
+
- 'spec/dummy/**/*'
|
16
|
+
- 'config/**/*'
|
17
|
+
- 'Rakefile'
|
18
|
+
- 'Gemfile'
|
19
|
+
|
20
|
+
Style/Documentation:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/BlockDelimiters:
|
24
|
+
Exclude:
|
25
|
+
- 'spec/**/*'
|
26
|
+
|
27
|
+
Style/AlignParameters:
|
28
|
+
EnforcedStyle: with_fixed_indentation
|
29
|
+
|
30
|
+
Style/ClosingParenthesisIndentation:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Metrics/LineLength:
|
34
|
+
Max: 100
|
35
|
+
AllowURI: true
|
36
|
+
|
37
|
+
Style/FirstParameterIndentation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/MultilineMethodCallIndentation:
|
41
|
+
EnforcedStyle: indented
|
42
|
+
|
43
|
+
Style/IndentArray:
|
44
|
+
EnforcedStyle: consistent
|
45
|
+
|
46
|
+
Style/IndentHash:
|
47
|
+
EnforcedStyle: consistent
|
48
|
+
|
49
|
+
Style/SignalException:
|
50
|
+
EnforcedStyle: semantic
|
51
|
+
|
52
|
+
Style/BracesAroundHashParameters:
|
53
|
+
EnforcedStyle: context_dependent
|
54
|
+
|
55
|
+
Lint/EndAlignment:
|
56
|
+
AlignWith: variable
|
57
|
+
AutoCorrect: true
|
58
|
+
|
59
|
+
Style/AndOr:
|
60
|
+
EnforcedStyle: conditionals
|
61
|
+
|
62
|
+
Metrics/MethodLength:
|
63
|
+
Max: 15
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# RocketPants::Pagination
|
2
2
|
|
3
|
-
[![Gem Version](https://
|
4
|
-
[![Build Status](https://
|
5
|
-
[![Dependency Status](https://
|
6
|
-
[![Code Climate](https://
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/rocket_pants-pagination.svg?maxAge=3600&style=flat-square)](https://rubygems.org/gems/rocket_pants-pagination)
|
4
|
+
[![Build Status](https://img.shields.io/travis/alessandro1997/rocket_pants-pagination.svg?maxAge=3600&style=flat-square)](https://travis-ci.org/alessandro1997/rocket_pants-pagination)
|
5
|
+
[![Dependency Status](https://img.shields.io/gemnasium/alessandro1997/rocket_pants-pagination.svg?maxAge=3600&style=flat-square)](https://gemnasium.com/github.com/alessandro1997/rocket_pants-pagination)
|
6
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/alessandro1997/rocket_pants-pagination.svg?maxAge=3600&style=flat-square)](https://codeclimate.com/github/alessandro1997/rocket_pants-pagination)
|
7
7
|
|
8
8
|
Pagination support for [RocketPants](https://github.com/Sutto/rocket_pants).
|
9
9
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rocket_pants'
|
2
3
|
require 'active_model_serializers'
|
3
4
|
require 'will_paginate'
|
@@ -14,12 +15,11 @@ module RocketPants
|
|
14
15
|
# @author Alessandro Desantis <desa.alessandro@gmail.com>
|
15
16
|
#
|
16
17
|
module Pagination
|
17
|
-
autoload :SwaggerSchema, 'rocket_pants/pagination/swagger_schema'
|
18
|
-
|
19
18
|
#
|
20
19
|
# Reserved root keys
|
21
20
|
#
|
22
|
-
RESERVED_PAGINATION_KEYS =
|
21
|
+
RESERVED_PAGINATION_KEYS = %i(count pagination).freeze
|
22
|
+
private_constant :RESERVED_PAGINATION_KEYS
|
23
23
|
|
24
24
|
#
|
25
25
|
# Paginates the given relation.
|
@@ -47,7 +47,7 @@ module RocketPants
|
|
47
47
|
root_key, collection = extract_pagination_elements_from hash
|
48
48
|
|
49
49
|
response = {
|
50
|
-
|
50
|
+
root_key => ActiveModel::Serializer::CollectionSerializer.new(collection),
|
51
51
|
count: collection.count,
|
52
52
|
pagination: {
|
53
53
|
pages: collection.total_pages,
|
@@ -74,48 +74,26 @@ module RocketPants
|
|
74
74
|
#
|
75
75
|
def paginate_and_expose(hash)
|
76
76
|
root_key, collection = extract_pagination_elements_from hash
|
77
|
-
expose_with_pagination
|
77
|
+
expose_with_pagination root_key => paginate(collection)
|
78
78
|
end
|
79
79
|
|
80
80
|
private
|
81
81
|
|
82
|
-
#
|
83
|
-
# Returns the first pair from the given hash.
|
84
|
-
#
|
85
|
-
# This is used to extract the root key and collection from a hash.
|
86
|
-
#
|
87
|
-
# @param [Hash(Symbol => ActiveRecord::Relation)] a hash with exactly one
|
88
|
-
# element, its key being the root key and its value a relation
|
89
|
-
#
|
90
|
-
# @return [Array(Symbol, ActiveRecord::Relation)] an array containing a root
|
91
|
-
# key and a relation
|
92
|
-
#
|
93
|
-
# @raise [ArgumentError] if the hash is malformed
|
94
|
-
#
|
95
82
|
def extract_pagination_elements_from(hash)
|
96
83
|
validate_pagination_hash! hash
|
97
84
|
hash.first
|
98
85
|
end
|
99
86
|
|
100
|
-
#
|
101
|
-
# Validates the given hash.
|
102
|
-
#
|
103
|
-
# Ensures that the hash has exactly one element and that the first element's
|
104
|
-
# key is not a reserved one.
|
105
|
-
#
|
106
|
-
# @param [Hash] a hash to validate
|
107
|
-
#
|
108
|
-
# @raise [ArgumentError] if the hash doesn't have exactly 1 element
|
109
|
-
# @raise [ArgumentError] if the first element's key is a reserved one
|
110
|
-
#
|
111
87
|
def validate_pagination_hash!(hash)
|
112
|
-
|
113
|
-
|
114
|
-
|
88
|
+
fail(
|
89
|
+
ArgumentError,
|
90
|
+
"The hash should contain exactly 1 element (#{hash.size} given)"
|
91
|
+
) if hash.size != 1
|
115
92
|
|
116
|
-
|
117
|
-
|
118
|
-
|
93
|
+
fail(
|
94
|
+
ArgumentError,
|
95
|
+
"#{hash.keys.first} is a reserved root key"
|
96
|
+
) if hash.keys.first.to_sym.in?(RESERVED_PAGINATION_KEYS)
|
119
97
|
end
|
120
98
|
end
|
121
99
|
end
|
@@ -18,12 +18,14 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'rocket_pants', '~> 1.13'
|
22
|
-
spec.add_dependency 'will_paginate', '~> 3.0'
|
23
|
-
spec.add_dependency 'active_model_serializers', '~> 0.
|
21
|
+
spec.add_dependency 'rocket_pants', '~> 1.13.1'
|
22
|
+
spec.add_dependency 'will_paginate', '~> 3.1.0'
|
23
|
+
spec.add_dependency 'active_model_serializers', '~> 0.10.2'
|
24
24
|
|
25
|
-
spec.add_development_dependency 'bundler'
|
26
|
-
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
27
|
spec.add_development_dependency 'rspec'
|
28
28
|
spec.add_development_dependency 'fuubar'
|
29
|
+
spec.add_development_dependency 'rubocop'
|
30
|
+
spec.add_development_dependency 'rubocop-rspec'
|
29
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocket_pants-pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Desantis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rocket_pants
|
@@ -16,70 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.13.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.13.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: will_paginate
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: active_model_serializers
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.10.2
|
48
48
|
type: :runtime
|
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:
|
54
|
+
version: 0.10.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description:
|
112
140
|
email:
|
113
141
|
- desa.alessandro@gmail.com
|
@@ -117,6 +145,7 @@ extra_rdoc_files: []
|
|
117
145
|
files:
|
118
146
|
- ".gitignore"
|
119
147
|
- ".rspec"
|
148
|
+
- ".rubocop.yml"
|
120
149
|
- ".travis.yml"
|
121
150
|
- Gemfile
|
122
151
|
- LICENSE.txt
|
@@ -125,7 +154,6 @@ files:
|
|
125
154
|
- bin/console
|
126
155
|
- bin/setup
|
127
156
|
- lib/rocket_pants/pagination.rb
|
128
|
-
- lib/rocket_pants/pagination/swagger_schema.rb
|
129
157
|
- lib/rocket_pants/pagination/version.rb
|
130
158
|
- rocket_pants-pagination.gemspec
|
131
159
|
homepage: https://github.com/alessandro1997/rocket_pants-pagination
|
@@ -148,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
176
|
version: '0'
|
149
177
|
requirements: []
|
150
178
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.
|
179
|
+
rubygems_version: 2.5.1
|
152
180
|
signing_key:
|
153
181
|
specification_version: 4
|
154
182
|
summary: Pagination support for RocketPants.
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module RocketPants
|
2
|
-
module Pagination
|
3
|
-
module SwaggerSchema
|
4
|
-
include ::Swagger::Blocks
|
5
|
-
|
6
|
-
swagger_schema :RocketPants_Pagination do
|
7
|
-
key :required, [:pages, :current, :count, :per_page]
|
8
|
-
|
9
|
-
property :pages do
|
10
|
-
key :type, :integer
|
11
|
-
key :format, :int64
|
12
|
-
key :description, 'the number of pages'
|
13
|
-
key :default, 1
|
14
|
-
end
|
15
|
-
|
16
|
-
property :current do
|
17
|
-
key :type, :integer
|
18
|
-
key :format, :int64
|
19
|
-
key :description, 'the number of the current page'
|
20
|
-
key :default, 1
|
21
|
-
end
|
22
|
-
|
23
|
-
property :count do
|
24
|
-
key :type, :integer
|
25
|
-
key :format, :int64
|
26
|
-
key :description, 'the number of total items'
|
27
|
-
key :default, 1
|
28
|
-
end
|
29
|
-
|
30
|
-
property :per_page do
|
31
|
-
key :type, :integer
|
32
|
-
key :format, :int64
|
33
|
-
key :description, 'the number of items per page'
|
34
|
-
key :default, 1
|
35
|
-
end
|
36
|
-
|
37
|
-
property :previous do
|
38
|
-
key :type, :integer
|
39
|
-
key :format, :int64
|
40
|
-
key :description, 'the number of the previous page (if available)'
|
41
|
-
key :default, 1
|
42
|
-
end
|
43
|
-
|
44
|
-
property :next do
|
45
|
-
key :type, :integer
|
46
|
-
key :format, :int64
|
47
|
-
key :description, 'the number of the next page (if available)'
|
48
|
-
key :default, 1
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|