rest-api-generator 0.1.7 → 0.2.0

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
2
  SHA256:
3
- metadata.gz: f7576268dec99ae0feafe5da3a552dae8d0609ccd244f5e62a99007e2f54090b
4
- data.tar.gz: 0f8a227490885ada7b83f1373c854857889e710b1d24285a81b45490308419a6
3
+ metadata.gz: b15131fc7fcedabae2098ef8f2e5e255683acda454d022304ea855ac9ce0a98a
4
+ data.tar.gz: 413967d92aca8c5c65075a8dfd5d0159be5c00b29a918b5bc3a39275217b3b6b
5
5
  SHA512:
6
- metadata.gz: 19bbdd850d24d6168fda588274287ad8645b255165487261dd6413420ab395fdc150675d97ed57ac6e2d395f2bf7cc5d48632f3b43bfe2a11f06964aae71b1d7
7
- data.tar.gz: 4653ea0a74f2377c9052eba66bb16230096598f5f3e5d52f42ff5ad5141b763b4054359c7bf360083d7e08b517249bf44b17a9a6e64765f51861961075068c65
6
+ metadata.gz: 439eb464b272818413629d6ca448c1e976603d97543600f521ff9386ba47e514c4a380b367c087a75a96cdeb5a501d707b365ca5d52d35a4cd3adf08fbddf9ec
7
+ data.tar.gz: 79ec324210477f42878cadebaf87566083c6db14251de20206a2cb2a98f2fd9bcbaba969170ecc3cfcee5dae89a51a37381aeaddb29fe30c7fd4d817d769f2de
data/Gemfile CHANGED
@@ -12,3 +12,9 @@ gem "rspec", "~> 3.0"
12
12
  gem "switchcop"
13
13
 
14
14
  gem "sqlite3"
15
+
16
+ # Serializers
17
+
18
+ gem "panko_serializer"
19
+
20
+ gem "active_model_serializers", "~> 0.10.0"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest-api-generator (0.1.7)
4
+ rest-api-generator (0.2.0)
5
5
  anyway_config (>= 2.0.0)
6
6
  pagy
7
7
  rails (>= 5.0)
@@ -9,86 +9,93 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actioncable (7.0.4)
13
- actionpack (= 7.0.4)
14
- activesupport (= 7.0.4)
12
+ actioncable (7.0.4.3)
13
+ actionpack (= 7.0.4.3)
14
+ activesupport (= 7.0.4.3)
15
15
  nio4r (~> 2.0)
16
16
  websocket-driver (>= 0.6.1)
17
- actionmailbox (7.0.4)
18
- actionpack (= 7.0.4)
19
- activejob (= 7.0.4)
20
- activerecord (= 7.0.4)
21
- activestorage (= 7.0.4)
22
- activesupport (= 7.0.4)
17
+ actionmailbox (7.0.4.3)
18
+ actionpack (= 7.0.4.3)
19
+ activejob (= 7.0.4.3)
20
+ activerecord (= 7.0.4.3)
21
+ activestorage (= 7.0.4.3)
22
+ activesupport (= 7.0.4.3)
23
23
  mail (>= 2.7.1)
24
24
  net-imap
25
25
  net-pop
26
26
  net-smtp
27
- actionmailer (7.0.4)
28
- actionpack (= 7.0.4)
29
- actionview (= 7.0.4)
30
- activejob (= 7.0.4)
31
- activesupport (= 7.0.4)
27
+ actionmailer (7.0.4.3)
28
+ actionpack (= 7.0.4.3)
29
+ actionview (= 7.0.4.3)
30
+ activejob (= 7.0.4.3)
31
+ activesupport (= 7.0.4.3)
32
32
  mail (~> 2.5, >= 2.5.4)
33
33
  net-imap
34
34
  net-pop
35
35
  net-smtp
36
36
  rails-dom-testing (~> 2.0)
37
- actionpack (7.0.4)
38
- actionview (= 7.0.4)
39
- activesupport (= 7.0.4)
37
+ actionpack (7.0.4.3)
38
+ actionview (= 7.0.4.3)
39
+ activesupport (= 7.0.4.3)
40
40
  rack (~> 2.0, >= 2.2.0)
41
41
  rack-test (>= 0.6.3)
42
42
  rails-dom-testing (~> 2.0)
43
43
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
44
- actiontext (7.0.4)
45
- actionpack (= 7.0.4)
46
- activerecord (= 7.0.4)
47
- activestorage (= 7.0.4)
48
- activesupport (= 7.0.4)
44
+ actiontext (7.0.4.3)
45
+ actionpack (= 7.0.4.3)
46
+ activerecord (= 7.0.4.3)
47
+ activestorage (= 7.0.4.3)
48
+ activesupport (= 7.0.4.3)
49
49
  globalid (>= 0.6.0)
50
50
  nokogiri (>= 1.8.5)
51
- actionview (7.0.4)
52
- activesupport (= 7.0.4)
51
+ actionview (7.0.4.3)
52
+ activesupport (= 7.0.4.3)
53
53
  builder (~> 3.1)
54
54
  erubi (~> 1.4)
55
55
  rails-dom-testing (~> 2.0)
56
56
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
57
- activejob (7.0.4)
58
- activesupport (= 7.0.4)
57
+ active_model_serializers (0.10.13)
58
+ actionpack (>= 4.1, < 7.1)
59
+ activemodel (>= 4.1, < 7.1)
60
+ case_transform (>= 0.2)
61
+ jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
62
+ activejob (7.0.4.3)
63
+ activesupport (= 7.0.4.3)
59
64
  globalid (>= 0.3.6)
60
- activemodel (7.0.4)
61
- activesupport (= 7.0.4)
62
- activerecord (7.0.4)
63
- activemodel (= 7.0.4)
64
- activesupport (= 7.0.4)
65
- activestorage (7.0.4)
66
- actionpack (= 7.0.4)
67
- activejob (= 7.0.4)
68
- activerecord (= 7.0.4)
69
- activesupport (= 7.0.4)
65
+ activemodel (7.0.4.3)
66
+ activesupport (= 7.0.4.3)
67
+ activerecord (7.0.4.3)
68
+ activemodel (= 7.0.4.3)
69
+ activesupport (= 7.0.4.3)
70
+ activestorage (7.0.4.3)
71
+ actionpack (= 7.0.4.3)
72
+ activejob (= 7.0.4.3)
73
+ activerecord (= 7.0.4.3)
74
+ activesupport (= 7.0.4.3)
70
75
  marcel (~> 1.0)
71
76
  mini_mime (>= 1.1.0)
72
- activesupport (7.0.4)
77
+ activesupport (7.0.4.3)
73
78
  concurrent-ruby (~> 1.0, >= 1.0.2)
74
79
  i18n (>= 1.6, < 2)
75
80
  minitest (>= 5.1)
76
81
  tzinfo (~> 2.0)
77
- addressable (2.8.1)
82
+ addressable (2.8.4)
78
83
  public_suffix (>= 2.0.2, < 6.0)
79
84
  ammeter (1.1.5)
80
85
  activesupport (>= 3.0)
81
86
  railties (>= 3.0)
82
87
  rspec-rails (>= 2.2)
83
- anyway_config (2.4.0)
88
+ anyway_config (2.4.1)
84
89
  ruby-next-core (>= 0.14.0)
85
90
  ast (2.4.2)
86
91
  builder (3.2.4)
87
- concurrent-ruby (1.1.10)
92
+ case_transform (0.2)
93
+ activesupport
94
+ concurrent-ruby (1.2.2)
88
95
  crass (1.0.6)
89
- database_cleaner (2.0.1)
90
- database_cleaner-active_record (~> 2.0.0)
91
- database_cleaner-active_record (2.0.1)
96
+ database_cleaner (2.0.2)
97
+ database_cleaner-active_record (>= 2, < 3)
98
+ database_cleaner-active_record (2.1.0)
92
99
  activerecord (>= 5.a)
93
100
  database_cleaner-core (~> 2.0.0)
94
101
  database_cleaner-core (2.0.1)
@@ -97,14 +104,15 @@ GEM
97
104
  erubi (1.12.0)
98
105
  globalid (1.1.0)
99
106
  activesupport (>= 5.0)
100
- i18n (1.12.0)
107
+ i18n (1.13.0)
101
108
  concurrent-ruby (~> 1.0)
102
109
  json (2.6.3)
103
110
  json-schema (3.0.0)
104
111
  addressable (>= 2.8)
105
- loofah (2.19.1)
112
+ jsonapi-renderer (0.2.2)
113
+ loofah (2.21.2)
106
114
  crass (~> 1.0.2)
107
- nokogiri (>= 1.5.9)
115
+ nokogiri (>= 1.12.0)
108
116
  mail (2.8.1)
109
117
  mini_mime (>= 0.1.1)
110
118
  net-imap
@@ -113,8 +121,8 @@ GEM
113
121
  marcel (1.0.2)
114
122
  method_source (1.0.0)
115
123
  mini_mime (1.1.2)
116
- mini_portile2 (2.8.1)
117
- minitest (5.16.3)
124
+ mini_portile2 (2.8.2)
125
+ minitest (5.18.0)
118
126
  net-imap (0.3.4)
119
127
  date
120
128
  net-protocol
@@ -125,136 +133,148 @@ GEM
125
133
  net-smtp (0.3.3)
126
134
  net-protocol
127
135
  nio4r (2.5.9)
128
- nokogiri (1.13.10)
136
+ nokogiri (1.14.4)
129
137
  mini_portile2 (~> 2.8.0)
130
138
  racc (~> 1.4)
131
- nokogiri (1.13.10-x86_64-linux)
139
+ nokogiri (1.14.4-x86_64-linux)
132
140
  racc (~> 1.4)
133
- pagy (6.0.3)
134
- parallel (1.22.1)
135
- parser (3.1.3.0)
141
+ oj (3.14.3)
142
+ pagy (6.0.4)
143
+ panko_serializer (0.7.9)
144
+ activesupport
145
+ oj (> 3.11.0, < 4.0.0)
146
+ parallel (1.23.0)
147
+ parser (3.2.2.1)
136
148
  ast (~> 2.4.1)
137
149
  public_suffix (5.0.1)
138
150
  racc (1.6.2)
139
- rack (2.2.4)
140
- rack-test (2.0.2)
151
+ rack (2.2.7)
152
+ rack-test (2.1.0)
141
153
  rack (>= 1.3)
142
- rails (7.0.4)
143
- actioncable (= 7.0.4)
144
- actionmailbox (= 7.0.4)
145
- actionmailer (= 7.0.4)
146
- actionpack (= 7.0.4)
147
- actiontext (= 7.0.4)
148
- actionview (= 7.0.4)
149
- activejob (= 7.0.4)
150
- activemodel (= 7.0.4)
151
- activerecord (= 7.0.4)
152
- activestorage (= 7.0.4)
153
- activesupport (= 7.0.4)
154
+ rails (7.0.4.3)
155
+ actioncable (= 7.0.4.3)
156
+ actionmailbox (= 7.0.4.3)
157
+ actionmailer (= 7.0.4.3)
158
+ actionpack (= 7.0.4.3)
159
+ actiontext (= 7.0.4.3)
160
+ actionview (= 7.0.4.3)
161
+ activejob (= 7.0.4.3)
162
+ activemodel (= 7.0.4.3)
163
+ activerecord (= 7.0.4.3)
164
+ activestorage (= 7.0.4.3)
165
+ activesupport (= 7.0.4.3)
154
166
  bundler (>= 1.15.0)
155
- railties (= 7.0.4)
167
+ railties (= 7.0.4.3)
156
168
  rails-dom-testing (2.0.3)
157
169
  activesupport (>= 4.2.0)
158
170
  nokogiri (>= 1.6)
159
- rails-html-sanitizer (1.4.4)
171
+ rails-html-sanitizer (1.5.0)
160
172
  loofah (~> 2.19, >= 2.19.1)
161
- railties (7.0.4)
162
- actionpack (= 7.0.4)
163
- activesupport (= 7.0.4)
173
+ railties (7.0.4.3)
174
+ actionpack (= 7.0.4.3)
175
+ activesupport (= 7.0.4.3)
164
176
  method_source
165
177
  rake (>= 12.2)
166
178
  thor (~> 1.0)
167
179
  zeitwerk (~> 2.5)
168
180
  rainbow (3.1.1)
169
181
  rake (13.0.6)
170
- regexp_parser (2.6.1)
182
+ regexp_parser (2.8.0)
171
183
  rexml (3.2.5)
172
184
  rspec (3.12.0)
173
185
  rspec-core (~> 3.12.0)
174
186
  rspec-expectations (~> 3.12.0)
175
187
  rspec-mocks (~> 3.12.0)
176
- rspec-core (3.12.0)
188
+ rspec-core (3.12.2)
177
189
  rspec-support (~> 3.12.0)
178
- rspec-expectations (3.12.1)
190
+ rspec-expectations (3.12.3)
179
191
  diff-lcs (>= 1.2.0, < 2.0)
180
192
  rspec-support (~> 3.12.0)
181
- rspec-mocks (3.12.1)
193
+ rspec-mocks (3.12.5)
182
194
  diff-lcs (>= 1.2.0, < 2.0)
183
195
  rspec-support (~> 3.12.0)
184
- rspec-rails (6.0.1)
196
+ rspec-rails (6.0.2)
185
197
  actionpack (>= 6.1)
186
198
  activesupport (>= 6.1)
187
199
  railties (>= 6.1)
188
- rspec-core (~> 3.11)
189
- rspec-expectations (~> 3.11)
190
- rspec-mocks (~> 3.11)
191
- rspec-support (~> 3.11)
200
+ rspec-core (~> 3.12)
201
+ rspec-expectations (~> 3.12)
202
+ rspec-mocks (~> 3.12)
203
+ rspec-support (~> 3.12)
192
204
  rspec-support (3.12.0)
193
- rswag (2.8.0)
194
- rswag-api (= 2.8.0)
195
- rswag-specs (= 2.8.0)
196
- rswag-ui (= 2.8.0)
197
- rswag-api (2.8.0)
205
+ rswag (2.9.0)
206
+ rswag-api (= 2.9.0)
207
+ rswag-specs (= 2.9.0)
208
+ rswag-ui (= 2.9.0)
209
+ rswag-api (2.9.0)
198
210
  railties (>= 3.1, < 7.1)
199
- rswag-specs (2.8.0)
211
+ rswag-specs (2.9.0)
200
212
  activesupport (>= 3.1, < 7.1)
201
213
  json-schema (>= 2.2, < 4.0)
202
214
  railties (>= 3.1, < 7.1)
203
215
  rspec-core (>= 2.14)
204
- rswag-ui (2.8.0)
216
+ rswag-ui (2.9.0)
205
217
  actionpack (>= 3.1, < 7.1)
206
218
  railties (>= 3.1, < 7.1)
207
- rubocop (1.40.0)
219
+ rubocop (1.51.0)
208
220
  json (~> 2.3)
209
221
  parallel (~> 1.10)
210
- parser (>= 3.1.2.1)
222
+ parser (>= 3.2.0.0)
211
223
  rainbow (>= 2.2.2, < 4.0)
212
224
  regexp_parser (>= 1.8, < 3.0)
213
225
  rexml (>= 3.2.5, < 4.0)
214
- rubocop-ast (>= 1.23.0, < 2.0)
226
+ rubocop-ast (>= 1.28.0, < 2.0)
215
227
  ruby-progressbar (~> 1.7)
216
- unicode-display_width (>= 1.4.0, < 3.0)
217
- rubocop-ast (1.24.0)
218
- parser (>= 3.1.1.0)
219
- rubocop-performance (1.15.2)
228
+ unicode-display_width (>= 2.4.0, < 3.0)
229
+ rubocop-ast (1.28.1)
230
+ parser (>= 3.2.1.0)
231
+ rubocop-capybara (2.18.0)
232
+ rubocop (~> 1.41)
233
+ rubocop-factory_bot (2.22.0)
234
+ rubocop (~> 1.33)
235
+ rubocop-performance (1.17.1)
220
236
  rubocop (>= 1.7.0, < 2.0)
221
237
  rubocop-ast (>= 0.4.0)
222
- rubocop-rails (2.17.4)
238
+ rubocop-rails (2.19.1)
223
239
  activesupport (>= 4.2.0)
224
240
  rack (>= 1.1)
225
241
  rubocop (>= 1.33.0, < 2.0)
226
- rubocop-rspec (2.16.0)
242
+ rubocop-rspec (2.22.0)
227
243
  rubocop (~> 1.33)
228
- rubocop-shopify (2.10.1)
229
- rubocop (~> 1.35)
244
+ rubocop-capybara (~> 2.17)
245
+ rubocop-factory_bot (~> 2.22)
246
+ rubocop-shopify (2.13.0)
247
+ rubocop (~> 1.50)
230
248
  ruby-next-core (0.15.3)
231
- ruby-progressbar (1.11.0)
232
- sqlite3 (1.5.4)
249
+ ruby-progressbar (1.13.0)
250
+ sqlite3 (1.6.2)
233
251
  mini_portile2 (~> 2.8.0)
234
- sqlite3 (1.5.4-x86_64-linux)
235
- switchcop (0.1.2)
236
- rubocop (~> 1.40.0)
237
- rubocop-performance (~> 1.15.1)
238
- rubocop-rails (~> 2.17.3)
239
- rubocop-rspec (~> 2.16.0)
240
- rubocop-shopify (~> 2.10.1)
241
- thor (1.2.1)
252
+ sqlite3 (1.6.2-x86_64-linux)
253
+ switchcop (0.1.3)
254
+ rubocop (~> 1.48)
255
+ rubocop-performance (~> 1.16)
256
+ rubocop-rails (~> 2.18)
257
+ rubocop-rspec (~> 2.19)
258
+ rubocop-shopify (~> 2.12)
259
+ thor (1.2.2)
242
260
  timeout (0.3.2)
243
- tzinfo (2.0.5)
261
+ tzinfo (2.0.6)
244
262
  concurrent-ruby (~> 1.0)
245
- unicode-display_width (2.3.0)
263
+ unicode-display_width (2.4.2)
246
264
  websocket-driver (0.7.5)
247
265
  websocket-extensions (>= 0.1.0)
248
266
  websocket-extensions (0.1.5)
249
- zeitwerk (2.6.6)
267
+ zeitwerk (2.6.8)
250
268
 
251
269
  PLATFORMS
252
270
  ruby
253
271
  x86_64-linux
254
272
 
255
273
  DEPENDENCIES
274
+ active_model_serializers (~> 0.10.0)
256
275
  ammeter (~> 1.1.5)
257
276
  database_cleaner
277
+ panko_serializer
258
278
  rake (~> 13.0)
259
279
  rest-api-generator!
260
280
  rspec (~> 3.0)
data/README.md CHANGED
@@ -25,13 +25,11 @@ Following [Switch Dreams's](https://www.switchdreams.com.br/]) coding practices,
25
25
  - [Resource ordering](#ordering)
26
26
  - [Resource filter](#filtering)
27
27
  - [Resource pagination](#pagination)
28
+ - [Resource serialization](#serialization)
28
29
  - [Configurable](#configuration)
29
30
 
30
31
  ## Next Features
31
32
 
32
- - Serialization https://github.com/SwitchDreams/rest-api-generator/issues/14
33
- https://github.com/SwitchDreams/rest-api-generator/issues/11
34
- - Pagination https://github.com/SwitchDreams/rest-api-generator/issues/15
35
33
  - Integration with AVO
36
34
  - Select fields
37
35
  - User auth module
@@ -250,7 +248,6 @@ rails g rest_api_generator:spec:rswag Car name:string color:string
250
248
  By default, the plain rspec and rswag specs are going to be generated in the _spec/requests_ and _spec/docs_
251
249
  directories, respectively. You can override using the (config options)[#configuration]]. :
252
250
 
253
-
254
251
  ### Resource Features
255
252
 
256
253
  #### Modular Error Handler
@@ -297,7 +294,8 @@ And It's done, you can filter your index end-point:
297
294
 
298
295
  ### Pagination
299
296
 
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.
297
+ For pagination, you need to create pagy initialializer file (pagy.rb) in the config directory of your project.
298
+ Follow [pagy's example](https://ddnexus.github.io/pagy/quick-start/) for more information.
301
299
 
302
300
  Next, you should add some lines on top of the previously created pagy file:
303
301
 
@@ -323,9 +321,45 @@ class NewParentController < ActionController::Base
323
321
  end
324
322
  ```
325
323
 
324
+ ### Serialization
325
+
326
+ If you are working with [ams](https://github.com/rails-api/active_model_serializers), the serializer will work without
327
+ any extra configuration.
328
+ But if you need to customize you can override the serializer method in the controller:
329
+
330
+ ```ruby
331
+ # Example with panko serializer: https://github.com/panko-serializer/panko_serializer
332
+ class CarsController < RestApiGenerator::ResourceController
333
+
334
+ # serializer used in show, create, update.
335
+ def serializer(resource)
336
+ Panko::CarSerializer.new.serialize_to_json(resource)
337
+ end
338
+
339
+ # serializer used in index.
340
+ def index_serializer(resources)
341
+ Panko::ArraySerializer.new(resources, each_serializer: Panko::CarSerializer).to_json
342
+ end
343
+ end
344
+ ```
345
+
346
+ ```ruby
347
+ # Example with ams
348
+ class CarsController < RestApiGenerator::ResourceController
349
+ def serializer(resource)
350
+ ActiveModelSerializers::SerializableResource.new(resource, each_serializer: Ams::CarSerializer).to_json
351
+ end
352
+ end
353
+ ```
354
+
355
+ The gem is tested with [panko serializer](https://github.com/panko-serializer/panko_serializer)
356
+ and [ams](https://github.com/rails-api/active_model_serializers). But should works with any serializer, feel free to add
357
+ tests for your favorite serializer.
358
+
326
359
  ## Configuration
327
360
 
328
- You can override this gem configuration using the initializer or any other method from [anyway_config](https://github.com/palkan/anyway_config):
361
+ You can override this gem configuration using the initializer or any other method
362
+ from [anyway_config](https://github.com/palkan/anyway_config):
329
363
 
330
364
  ```rb
331
365
  # config/initializers/rest_api_generator.rb
@@ -3,6 +3,7 @@
3
3
  module RestApiGenerator
4
4
  class ChildResourceController < RestApiGenerator.configuration.parent_controller.constantize
5
5
  include Orderable
6
+ include Serializable
6
7
 
7
8
  before_action :set_parent_resource
8
9
  before_action :set_resource, only: [:show, :update, :destroy]
@@ -15,21 +16,21 @@ module RestApiGenerator
15
16
  @pagy, @resources = pagy(@resources)
16
17
  pagy_headers_merge(@pagy)
17
18
  end
18
- render json: @resources, status: :ok
19
+ render json: index_serializer(@resources), status: :ok
19
20
  end
20
21
 
21
22
  def show
22
- render json: @resource, status: :ok
23
+ render json: serializer(@resource), status: :ok
23
24
  end
24
25
 
25
26
  def create
26
27
  @resource = resources.create!(resource_created_params)
27
- render json: @resource, status: :created
28
+ render json: serializer(@resource), status: :created
28
29
  end
29
30
 
30
31
  def update
31
32
  @resource.update!(resource_updated_params)
32
- render json: @resource, status: :ok
33
+ render json: serializer(@resource), status: :ok
33
34
  end
34
35
 
35
36
  def destroy
@@ -3,6 +3,7 @@
3
3
  module RestApiGenerator
4
4
  class ResourceController < RestApiGenerator.configuration.parent_controller.constantize
5
5
  include Orderable
6
+ include Serializable
6
7
 
7
8
  before_action :set_resource, only: [:show, :update, :destroy]
8
9
 
@@ -14,21 +15,21 @@ module RestApiGenerator
14
15
  @pagy, @resources = pagy(@resources)
15
16
  pagy_headers_merge(@pagy)
16
17
  end
17
- render json: @resources, status: :ok
18
+ render json: index_serializer(@resources), status: :ok
18
19
  end
19
20
 
20
21
  def show
21
- render json: @resource, status: :ok
22
+ render json: serializer(@resource), status: :ok
22
23
  end
23
24
 
24
25
  def create
25
26
  @resource = resource_class.create!(resource_created_params)
26
- render json: @resource, status: :created
27
+ render json: serializer(@resource), status: :created
27
28
  end
28
29
 
29
30
  def update
30
31
  @resource.update!(resource_updated_params)
31
- render json: @resource, status: :ok
32
+ render json: serializer(@resource), status: :ok
32
33
  end
33
34
 
34
35
  def destroy
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_support/concern"
5
+
6
+ module RestApiGenerator
7
+ module Serializable
8
+ extend ActiveSupport::Concern
9
+
10
+ def serializer(resource)
11
+ resource
12
+ end
13
+
14
+ def index_serializer(resources)
15
+ serializer(resources)
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RestApiGenerator
4
- VERSION = "0.1.7"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -8,6 +8,7 @@ require_relative "rest_api_generator/custom_error"
8
8
  require_relative "rest_api_generator/helpers/render"
9
9
  require_relative "rest_api_generator/filterable"
10
10
  require_relative "rest_api_generator/orderable"
11
+ require_relative "rest_api_generator/serializable"
11
12
 
12
13
  module RestApiGenerator
13
14
  class Error < StandardError; end
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.metadata["homepage_uri"] = spec.homepage
22
22
  spec.metadata["source_code_uri"] = "https://github.com/SwitchDreams/rest-api-generator"
23
23
  spec.metadata["changelog_uri"] = "https://github.com/SwitchDreams/rest-api-generator"
24
+ spec.metadata["github_repo"] = "https://github.com/SwitchDreams/rest-api-generator"
24
25
 
25
26
  spec.files = Dir["{bin,sig,lib,public,app}/**/*",
26
27
  "MIT-LICENSE",
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.7
4
+ version: 0.2.0
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-26 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anyway_config
@@ -161,6 +161,7 @@ files:
161
161
  - lib/rest_api_generator/helpers/render.rb
162
162
  - lib/rest_api_generator/orderable.rb
163
163
  - lib/rest_api_generator/rails.rb
164
+ - lib/rest_api_generator/serializable.rb
164
165
  - lib/rest_api_generator/version.rb
165
166
  - rest-api-generator.gemspec
166
167
  - sig/rest_api_generator.rbs
@@ -172,6 +173,7 @@ metadata:
172
173
  homepage_uri: https://github.com/SwitchDreams/rest-api-generator
173
174
  source_code_uri: https://github.com/SwitchDreams/rest-api-generator
174
175
  changelog_uri: https://github.com/SwitchDreams/rest-api-generator
176
+ github_repo: https://github.com/SwitchDreams/rest-api-generator
175
177
  rubygems_mfa_required: 'true'
176
178
  post_install_message:
177
179
  rdoc_options: []