rest-api-generator 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
2
  SHA256:
3
- metadata.gz: 2856805f0d16c6778be959778e29681c2e6ce306d9b3699e6e766da7f605948b
4
- data.tar.gz: f9ffabaa5ee380f54ab19a8ad88ddd58de27ee968e44e4ad64794d0110b6979f
3
+ metadata.gz: f7576268dec99ae0feafe5da3a552dae8d0609ccd244f5e62a99007e2f54090b
4
+ data.tar.gz: 0f8a227490885ada7b83f1373c854857889e710b1d24285a81b45490308419a6
5
5
  SHA512:
6
- metadata.gz: e92f35591532264731ac9acd69117082954c1ac342a89f298d40c60a11dfee9b02b9f2bc5f9e75251ced9937929d900bbfc8491a00b070220bed04c73f81f014
7
- data.tar.gz: 5914b7f9b6eb86efbf11ffb1497db57fa9ffec03ce9d4978cfae19e3d6425c52b5ab2fdc564c7baf3ec5acad478ec9d86cbccef19be253389176aee8bb7a2a3c
6
+ metadata.gz: 19bbdd850d24d6168fda588274287ad8645b255165487261dd6413420ab395fdc150675d97ed57ac6e2d395f2bf7cc5d48632f3b43bfe2a11f06964aae71b1d7
7
+ data.tar.gz: 4653ea0a74f2377c9052eba66bb16230096598f5f3e5d52f42ff5ad5141b763b4054359c7bf360083d7e08b517249bf44b17a9a6e64765f51861961075068c65
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest-api-generator (0.1.5)
4
+ rest-api-generator (0.1.7)
5
5
  anyway_config (>= 2.0.0)
6
+ pagy
6
7
  rails (>= 5.0)
7
8
 
8
9
  GEM
@@ -129,6 +130,7 @@ GEM
129
130
  racc (~> 1.4)
130
131
  nokogiri (1.13.10-x86_64-linux)
131
132
  racc (~> 1.4)
133
+ pagy (6.0.3)
132
134
  parallel (1.22.1)
133
135
  parser (3.1.3.0)
134
136
  ast (~> 2.4.1)
data/README.md CHANGED
@@ -24,6 +24,7 @@ Following [Switch Dreams's](https://www.switchdreams.com.br/]) coding practices,
24
24
  - :memo: [Automated documentation](#specsdocs)
25
25
  - [Resource ordering](#ordering)
26
26
  - [Resource filter](#filtering)
27
+ - [Resource pagination](#pagination)
27
28
  - [Configurable](#configuration)
28
29
 
29
30
  ## Next Features
@@ -294,6 +295,34 @@ And It's done, you can filter your index end-point:
294
295
 
295
296
  - `GET /cars?color=blue or GET /cars?color=red&name=Ferrari`
296
297
 
298
+ ### Pagination
299
+
300
+ For pagination, you need to create pagy initialializer file (pagy.rb) in the config directory of your project. Follow [pagy's example](https://ddnexus.github.io/pagy/quick-start/) for more information.
301
+
302
+ Next, you should add some lines on top of the previously created pagy file:
303
+
304
+ ```ruby
305
+ # config/initializers/pagy.rb
306
+ require "pagy"
307
+ require "pagy/extras/headers"
308
+ ```
309
+
310
+ At last, change the pagination variable on RestApiGenerator initializer to true;
311
+
312
+ ```rb
313
+ # config/initializers/rest_api_generator.rb
314
+ config.pagination = true # default: false
315
+ ```
316
+
317
+ Note, if the parent controller is changed, it is necessary to include Pagy::Backend in the new parent.
318
+
319
+ ```rb
320
+ # new_parent_controller.rb
321
+ class NewParentController < ActionController::Base
322
+ include Pagy::Backend
323
+ end
324
+ ```
325
+
297
326
  ## Configuration
298
327
 
299
328
  You can override this gem configuration using the initializer or any other method from [anyway_config](https://github.com/palkan/anyway_config):
@@ -305,6 +334,7 @@ RestApiGenerator.configure do |config|
305
334
  config.test_path = "custom_test_dir/requests" # default: spec/requests
306
335
  config.docs_path = "custom_docs_dir/rswag" # default: spec/docs
307
336
  config.parent_class = "ApplicationController" # default: RestApiGenerator::ResourceController
337
+ config.pagination = true # default: false
308
338
  end
309
339
  ```
310
340
 
@@ -4,5 +4,6 @@ require "action_controller"
4
4
 
5
5
  module RestApiGenerator
6
6
  class ApplicationController < ActionController::Base
7
+ include Pagy::Backend
7
8
  end
8
9
  end
@@ -11,6 +11,10 @@ module RestApiGenerator
11
11
  @resources = resources
12
12
  @resources = @resources.filter_resource(params_for_filter) if resource_class.include?(Filterable)
13
13
  @resources = @resources.order(ordering_params(params[:sort])) if params[:sort]
14
+ if pagination
15
+ @pagy, @resources = pagy(@resources)
16
+ pagy_headers_merge(@pagy)
17
+ end
14
18
  render json: @resources, status: :ok
15
19
  end
16
20
 
@@ -93,5 +97,9 @@ module RestApiGenerator
93
97
  def record_id
94
98
  params.permit(:id)[:id]
95
99
  end
100
+
101
+ def pagination
102
+ RestApiGenerator.configuration.pagination
103
+ end
96
104
  end
97
105
  end
@@ -10,6 +10,10 @@ module RestApiGenerator
10
10
  @resources = resource_class.all
11
11
  @resources = @resources.filter_resource(params_for_filter) if resource_class.include?(Filterable)
12
12
  @resources = @resources.order(ordering_params(params[:sort])) if params[:sort]
13
+ if pagination
14
+ @pagy, @resources = pagy(@resources)
15
+ pagy_headers_merge(@pagy)
16
+ end
13
17
  render json: @resources, status: :ok
14
18
  end
15
19
 
@@ -69,5 +73,9 @@ module RestApiGenerator
69
73
  def record_id
70
74
  params.permit(:id)[:id]
71
75
  end
76
+
77
+ def pagination
78
+ RestApiGenerator.configuration.pagination
79
+ end
72
80
  end
73
81
  end
@@ -10,6 +10,7 @@ module RestApiGenerator
10
10
 
11
11
  attr_config test_path: "spec/requests",
12
12
  docs_path: "spec/docs",
13
- parent_controller: "RestApiGenerator::ApplicationController"
13
+ parent_controller: "RestApiGenerator::ApplicationController",
14
+ pagination: false
14
15
  end
15
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RestApiGenerator
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
38
38
  spec.metadata["rubygems_mfa_required"] = "true"
39
39
 
40
40
  spec.add_dependency "anyway_config", ">= 2.0.0"
41
+ spec.add_dependency "pagy"
41
42
  spec.add_dependency "rails", ">= 5.0"
42
43
 
43
44
  spec.add_development_dependency "ammeter", "~> 1.1.5"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-api-generator
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
  - PedroAugustoRamalhoDuarte
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-11 00:00:00.000000000 Z
11
+ date: 2023-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anyway_config
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pagy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rails
29
43
  requirement: !ruby/object:Gem::Requirement