jat 0.0.3 → 0.0.5

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.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jat/attribute.rb +36 -4
  3. data/lib/jat/plugins/_activerecord_preloads/_activerecord_preloads.rb +7 -3
  4. data/lib/jat/plugins/_activerecord_preloads/lib/preloader.rb +7 -13
  5. data/lib/jat/plugins/_lower_camel_case/_lower_camel_case.rb +32 -0
  6. data/lib/jat/plugins/_preloads/_preloads.rb +8 -2
  7. data/lib/jat/plugins/cache/cache.rb +9 -5
  8. data/lib/jat/plugins/json_api/json_api.rb +145 -105
  9. data/lib/jat/plugins/json_api/lib/fields_param_parser.rb +40 -0
  10. data/lib/jat/plugins/json_api/lib/include_param_parser.rb +84 -0
  11. data/lib/jat/plugins/json_api/lib/map.rb +92 -27
  12. data/lib/jat/plugins/json_api/lib/params/fields/validate.rb +8 -5
  13. data/lib/jat/plugins/json_api/lib/response.rb +84 -196
  14. data/lib/jat/plugins/json_api/lib/response_piece.rb +166 -0
  15. data/lib/jat/plugins/json_api_activerecord/json_api_activerecord.rb +31 -0
  16. data/lib/jat/plugins/{_json_api_activerecord → json_api_activerecord}/lib/preloads.rb +16 -24
  17. data/lib/jat/plugins/json_api_lower_camel_case/json_api_lower_camel_case.rb +30 -0
  18. data/lib/jat/plugins/json_api_maps_cache/json_api_maps_cache.rb +54 -0
  19. data/lib/jat/plugins/json_api_validate_params/json_api_validate_params.rb +57 -0
  20. data/lib/jat/plugins/json_api_validate_params/lib/params_error.rb +6 -0
  21. data/lib/jat/plugins/json_api_validate_params/lib/validate_fields_param.rb +59 -0
  22. data/lib/jat/plugins/json_api_validate_params/lib/validate_include_param.rb +33 -0
  23. data/lib/jat/plugins/simple_api/lib/fields_param_parser.rb +97 -0
  24. data/lib/jat/plugins/simple_api/lib/map.rb +80 -10
  25. data/lib/jat/plugins/simple_api/lib/response.rb +78 -89
  26. data/lib/jat/plugins/simple_api/lib/response_piece.rb +84 -0
  27. data/lib/jat/plugins/simple_api/simple_api.rb +83 -24
  28. data/lib/jat/plugins/simple_api_activerecord/lib/preloads.rb +55 -0
  29. data/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord.rb +31 -0
  30. data/lib/jat/plugins/simple_api_lower_camel_case/simple_api_lower_camel_case.rb +30 -0
  31. data/lib/jat/plugins/simple_api_maps_cache/simple_api_maps_cache.rb +48 -0
  32. data/lib/jat/plugins/simple_api_validate_params/lib/fields_error.rb +6 -0
  33. data/lib/jat/plugins/simple_api_validate_params/lib/validate_fields_param.rb +45 -0
  34. data/lib/jat/plugins/simple_api_validate_params/simple_api_validate_params.rb +45 -0
  35. data/lib/jat/plugins/to_str/to_str.rb +10 -4
  36. data/lib/jat/plugins.rb +3 -16
  37. data/lib/jat.rb +28 -30
  38. data/test/lib/jat/attribute_test.rb +15 -5
  39. data/test/lib/jat/plugins/_activerecord_preloads/_activerecord_preloads_test.rb +34 -15
  40. data/test/lib/jat/plugins/_activerecord_preloads/lib/preloader_test.rb +10 -24
  41. data/test/lib/jat/plugins/_camel_lower/_camel_lower_test.rb +26 -0
  42. data/test/lib/jat/plugins/_preloads/lib/format_user_preloads_test.rb +1 -1
  43. data/test/lib/jat/plugins/_preloads/lib/preloads_with_path_test.rb +1 -1
  44. data/test/lib/jat/plugins/cache/cache_test.rb +11 -11
  45. data/test/lib/jat/plugins/json_api/json_api_test.rb +63 -47
  46. data/test/lib/jat/plugins/json_api/lib/{params/fields_test.rb → fields_param_parser_test.rb} +7 -6
  47. data/test/lib/jat/plugins/json_api/lib/{params/include_test.rb → include_param_parser_test.rb} +4 -4
  48. data/test/lib/jat/plugins/json_api/lib/map_test.rb +150 -79
  49. data/test/lib/jat/plugins/json_api/lib/response_test.rb +32 -32
  50. data/test/lib/jat/plugins/{_json_api_activerecord/_json_api_activerecord_test.rb → json_api_activerecord/json_api_activerecord_test.rb} +14 -5
  51. data/test/lib/jat/plugins/{_json_api_activerecord → json_api_activerecord}/lib/preloads_test.rb +11 -10
  52. data/test/lib/jat/plugins/json_api_camel_lower/json_api_camel_lower_test.rb +79 -0
  53. data/test/lib/jat/plugins/json_api_maps_cache/json_api_maps_cache_test.rb +107 -0
  54. data/test/lib/jat/plugins/json_api_validate_params/json_api_validate_params_test.rb +84 -0
  55. data/test/lib/jat/plugins/simple_api/lib/{params/parse_test.rb → fields_param_parser_test.rb} +10 -4
  56. data/test/lib/jat/plugins/simple_api/lib/map_test.rb +111 -34
  57. data/test/lib/jat/plugins/simple_api/lib/response_test.rb +80 -74
  58. data/test/lib/jat/plugins/simple_api/simple_api_test.rb +91 -25
  59. data/test/lib/jat/plugins/simple_api_activerecord/lib/preloads_test.rb +135 -0
  60. data/test/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord_test.rb +38 -0
  61. data/test/lib/jat/plugins/simple_api_camel_lower/simple_api_camel_lower_test.rb +48 -0
  62. data/test/lib/jat/plugins/simple_api_maps_cache/simple_api_maps_cache_test.rb +95 -0
  63. data/test/lib/jat/plugins/simple_api_validate_params/simple_api_validate_params_test.rb +89 -0
  64. data/test/lib/jat/plugins/to_str/to_str_test.rb +3 -3
  65. data/test/lib/jat_test.rb +47 -24
  66. data/test/lib/plugin_test.rb +3 -3
  67. data/test/test_helper.rb +0 -3
  68. data/test/test_plugin.rb +9 -12
  69. metadata +60 -71
  70. data/CHANGELOG.md +0 -7
  71. data/README.md +0 -21
  72. data/jat.gemspec +0 -37
  73. data/lib/jat/plugins/_json_api_activerecord/_json_api_activerecord.rb +0 -22
  74. data/lib/jat/plugins/camel_lower/camel_lower.rb +0 -18
  75. data/lib/jat/plugins/json_api/lib/construct_traversal_map.rb +0 -91
  76. data/lib/jat/plugins/json_api/lib/presenters/document_links_presenter.rb +0 -48
  77. data/lib/jat/plugins/json_api/lib/presenters/document_meta_presenter.rb +0 -48
  78. data/lib/jat/plugins/json_api/lib/presenters/jsonapi_presenter.rb +0 -48
  79. data/lib/jat/plugins/json_api/lib/presenters/links_presenter.rb +0 -48
  80. data/lib/jat/plugins/json_api/lib/presenters/meta_presenter.rb +0 -48
  81. data/lib/jat/plugins/json_api/lib/presenters/relationship_links_presenter.rb +0 -53
  82. data/lib/jat/plugins/json_api/lib/presenters/relationship_meta_presenter.rb +0 -53
  83. data/lib/jat/plugins/json_api/lib/traversal_map.rb +0 -34
  84. data/lib/jat/plugins/simple_api/lib/construct_traversal_map.rb +0 -45
  85. data/lib/jat/plugins/simple_api/lib/params/parse.rb +0 -68
  86. data/lib/jat/presenter.rb +0 -51
  87. data/test/lib/jat/plugins/camel_lower/camel_lower_test.rb +0 -78
  88. data/test/lib/jat/plugins/json_api/lib/construct_traversal_map_test.rb +0 -119
  89. data/test/lib/jat/plugins/json_api/lib/params/fields/parse_test.rb +0 -24
  90. data/test/lib/jat/plugins/json_api/lib/params/fields/validate_test.rb +0 -47
  91. data/test/lib/jat/plugins/json_api/lib/params/include/parse_test.rb +0 -46
  92. data/test/lib/jat/plugins/json_api/lib/params/include/validate_test.rb +0 -51
  93. data/test/lib/jat/plugins/json_api/lib/presenters/document_links_presenter_test.rb +0 -69
  94. data/test/lib/jat/plugins/json_api/lib/presenters/document_meta_presenter_test.rb +0 -69
  95. data/test/lib/jat/plugins/json_api/lib/presenters/jsonapi_presenter_test.rb +0 -69
  96. data/test/lib/jat/plugins/json_api/lib/presenters/links_presenter_test.rb +0 -69
  97. data/test/lib/jat/plugins/json_api/lib/presenters/meta_presenter_test.rb +0 -69
  98. data/test/lib/jat/plugins/json_api/lib/presenters/relationship_links_presenter_test.rb +0 -75
  99. data/test/lib/jat/plugins/json_api/lib/presenters/relationship_meta_presenter_test.rb +0 -75
  100. data/test/lib/jat/plugins/json_api/lib/traversal_map_test.rb +0 -58
  101. data/test/lib/jat/plugins/simple_api/lib/construct_traversal_map_test.rb +0 -100
  102. data/test/lib/jat/presenter_test.rb +0 -61
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Glushkov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-30 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -53,33 +53,33 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: standard
56
+ name: simplecov
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.0'
61
+ version: '0.21'
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: '1.0'
68
+ version: '0.21'
69
69
  - !ruby/object:Gem::Dependency
70
- name: simplecov
70
+ name: standard
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.21'
75
+ version: '1.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: '0.21'
82
+ version: '1.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activerecord
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -109,31 +109,27 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.4'
111
111
  description: |
112
- The JAT serializer allows you to generate a JSON response based on the fields requested by the client.
113
- Besides, it avoids manually adding includes and solves N+1 problems on its own.
112
+ JAT serializer allows you to generate a JSON response based on the fields requested by the client.
113
+ Besides, it helps to preload relations to avoid N+1 when used with activerecord.
114
114
  email: aglushkov@shakuro.com
115
115
  executables: []
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
- - CHANGELOG.md
120
- - README.md
121
- - jat.gemspec
122
119
  - lib/jat.rb
123
120
  - lib/jat/attribute.rb
124
121
  - lib/jat/config.rb
125
122
  - lib/jat/plugins.rb
126
123
  - lib/jat/plugins/_activerecord_preloads/_activerecord_preloads.rb
127
124
  - lib/jat/plugins/_activerecord_preloads/lib/preloader.rb
128
- - lib/jat/plugins/_json_api_activerecord/_json_api_activerecord.rb
129
- - lib/jat/plugins/_json_api_activerecord/lib/preloads.rb
125
+ - lib/jat/plugins/_lower_camel_case/_lower_camel_case.rb
130
126
  - lib/jat/plugins/_preloads/_preloads.rb
131
127
  - lib/jat/plugins/_preloads/lib/format_user_preloads.rb
132
128
  - lib/jat/plugins/_preloads/lib/preloads_with_path.rb
133
129
  - lib/jat/plugins/cache/cache.rb
134
- - lib/jat/plugins/camel_lower/camel_lower.rb
135
130
  - lib/jat/plugins/json_api/json_api.rb
136
- - lib/jat/plugins/json_api/lib/construct_traversal_map.rb
131
+ - lib/jat/plugins/json_api/lib/fields_param_parser.rb
132
+ - lib/jat/plugins/json_api/lib/include_param_parser.rb
137
133
  - lib/jat/plugins/json_api/lib/map.rb
138
134
  - lib/jat/plugins/json_api/lib/params/fields.rb
139
135
  - lib/jat/plugins/json_api/lib/params/fields/parse.rb
@@ -141,60 +137,60 @@ files:
141
137
  - lib/jat/plugins/json_api/lib/params/include.rb
142
138
  - lib/jat/plugins/json_api/lib/params/include/parse.rb
143
139
  - lib/jat/plugins/json_api/lib/params/include/validate.rb
144
- - lib/jat/plugins/json_api/lib/presenters/document_links_presenter.rb
145
- - lib/jat/plugins/json_api/lib/presenters/document_meta_presenter.rb
146
- - lib/jat/plugins/json_api/lib/presenters/jsonapi_presenter.rb
147
- - lib/jat/plugins/json_api/lib/presenters/links_presenter.rb
148
- - lib/jat/plugins/json_api/lib/presenters/meta_presenter.rb
149
- - lib/jat/plugins/json_api/lib/presenters/relationship_links_presenter.rb
150
- - lib/jat/plugins/json_api/lib/presenters/relationship_meta_presenter.rb
151
140
  - lib/jat/plugins/json_api/lib/response.rb
152
- - lib/jat/plugins/json_api/lib/traversal_map.rb
153
- - lib/jat/plugins/simple_api/lib/construct_traversal_map.rb
141
+ - lib/jat/plugins/json_api/lib/response_piece.rb
142
+ - lib/jat/plugins/json_api_activerecord/json_api_activerecord.rb
143
+ - lib/jat/plugins/json_api_activerecord/lib/preloads.rb
144
+ - lib/jat/plugins/json_api_lower_camel_case/json_api_lower_camel_case.rb
145
+ - lib/jat/plugins/json_api_maps_cache/json_api_maps_cache.rb
146
+ - lib/jat/plugins/json_api_validate_params/json_api_validate_params.rb
147
+ - lib/jat/plugins/json_api_validate_params/lib/params_error.rb
148
+ - lib/jat/plugins/json_api_validate_params/lib/validate_fields_param.rb
149
+ - lib/jat/plugins/json_api_validate_params/lib/validate_include_param.rb
150
+ - lib/jat/plugins/simple_api/lib/fields_param_parser.rb
154
151
  - lib/jat/plugins/simple_api/lib/map.rb
155
- - lib/jat/plugins/simple_api/lib/params/parse.rb
156
152
  - lib/jat/plugins/simple_api/lib/response.rb
153
+ - lib/jat/plugins/simple_api/lib/response_piece.rb
157
154
  - lib/jat/plugins/simple_api/simple_api.rb
155
+ - lib/jat/plugins/simple_api_activerecord/lib/preloads.rb
156
+ - lib/jat/plugins/simple_api_activerecord/simple_api_activerecord.rb
157
+ - lib/jat/plugins/simple_api_lower_camel_case/simple_api_lower_camel_case.rb
158
+ - lib/jat/plugins/simple_api_maps_cache/simple_api_maps_cache.rb
159
+ - lib/jat/plugins/simple_api_validate_params/lib/fields_error.rb
160
+ - lib/jat/plugins/simple_api_validate_params/lib/validate_fields_param.rb
161
+ - lib/jat/plugins/simple_api_validate_params/simple_api_validate_params.rb
158
162
  - lib/jat/plugins/to_str/to_str.rb
159
- - lib/jat/presenter.rb
160
163
  - lib/jat/utils/enum_deep_dup.rb
161
164
  - lib/jat/utils/enum_deep_freeze.rb
162
165
  - test/lib/jat/attribute_test.rb
163
166
  - test/lib/jat/config_test.rb
164
167
  - test/lib/jat/plugins/_activerecord_preloads/_activerecord_preloads_test.rb
165
168
  - test/lib/jat/plugins/_activerecord_preloads/lib/preloader_test.rb
166
- - test/lib/jat/plugins/_json_api_activerecord/_json_api_activerecord_test.rb
167
- - test/lib/jat/plugins/_json_api_activerecord/lib/preloads_test.rb
169
+ - test/lib/jat/plugins/_camel_lower/_camel_lower_test.rb
168
170
  - test/lib/jat/plugins/_preloads/_preloads_test.rb
169
171
  - test/lib/jat/plugins/_preloads/lib/format_user_preloads_test.rb
170
172
  - test/lib/jat/plugins/_preloads/lib/preloads_with_path_test.rb
171
173
  - test/lib/jat/plugins/cache/cache_test.rb
172
- - test/lib/jat/plugins/camel_lower/camel_lower_test.rb
173
174
  - test/lib/jat/plugins/json_api/json_api_test.rb
174
- - test/lib/jat/plugins/json_api/lib/construct_traversal_map_test.rb
175
+ - test/lib/jat/plugins/json_api/lib/fields_param_parser_test.rb
176
+ - test/lib/jat/plugins/json_api/lib/include_param_parser_test.rb
175
177
  - test/lib/jat/plugins/json_api/lib/map_test.rb
176
- - test/lib/jat/plugins/json_api/lib/params/fields/parse_test.rb
177
- - test/lib/jat/plugins/json_api/lib/params/fields/validate_test.rb
178
- - test/lib/jat/plugins/json_api/lib/params/fields_test.rb
179
- - test/lib/jat/plugins/json_api/lib/params/include/parse_test.rb
180
- - test/lib/jat/plugins/json_api/lib/params/include/validate_test.rb
181
- - test/lib/jat/plugins/json_api/lib/params/include_test.rb
182
- - test/lib/jat/plugins/json_api/lib/presenters/document_links_presenter_test.rb
183
- - test/lib/jat/plugins/json_api/lib/presenters/document_meta_presenter_test.rb
184
- - test/lib/jat/plugins/json_api/lib/presenters/jsonapi_presenter_test.rb
185
- - test/lib/jat/plugins/json_api/lib/presenters/links_presenter_test.rb
186
- - test/lib/jat/plugins/json_api/lib/presenters/meta_presenter_test.rb
187
- - test/lib/jat/plugins/json_api/lib/presenters/relationship_links_presenter_test.rb
188
- - test/lib/jat/plugins/json_api/lib/presenters/relationship_meta_presenter_test.rb
189
178
  - test/lib/jat/plugins/json_api/lib/response_test.rb
190
- - test/lib/jat/plugins/json_api/lib/traversal_map_test.rb
191
- - test/lib/jat/plugins/simple_api/lib/construct_traversal_map_test.rb
179
+ - test/lib/jat/plugins/json_api_activerecord/json_api_activerecord_test.rb
180
+ - test/lib/jat/plugins/json_api_activerecord/lib/preloads_test.rb
181
+ - test/lib/jat/plugins/json_api_camel_lower/json_api_camel_lower_test.rb
182
+ - test/lib/jat/plugins/json_api_maps_cache/json_api_maps_cache_test.rb
183
+ - test/lib/jat/plugins/json_api_validate_params/json_api_validate_params_test.rb
184
+ - test/lib/jat/plugins/simple_api/lib/fields_param_parser_test.rb
192
185
  - test/lib/jat/plugins/simple_api/lib/map_test.rb
193
- - test/lib/jat/plugins/simple_api/lib/params/parse_test.rb
194
186
  - test/lib/jat/plugins/simple_api/lib/response_test.rb
195
187
  - test/lib/jat/plugins/simple_api/simple_api_test.rb
188
+ - test/lib/jat/plugins/simple_api_activerecord/lib/preloads_test.rb
189
+ - test/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord_test.rb
190
+ - test/lib/jat/plugins/simple_api_camel_lower/simple_api_camel_lower_test.rb
191
+ - test/lib/jat/plugins/simple_api_maps_cache/simple_api_maps_cache_test.rb
192
+ - test/lib/jat/plugins/simple_api_validate_params/simple_api_validate_params_test.rb
196
193
  - test/lib/jat/plugins/to_str/to_str_test.rb
197
- - test/lib/jat/presenter_test.rb
198
194
  - test/lib/jat/utils/enum_deep_dup_test.rb
199
195
  - test/lib/jat/utils/enum_deep_freeze_test.rb
200
196
  - test/lib/jat_test.rb
@@ -224,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
220
  - !ruby/object:Gem::Version
225
221
  version: '0'
226
222
  requirements: []
227
- rubygems_version: 3.2.1
223
+ rubygems_version: 3.2.22
228
224
  signing_key:
229
225
  specification_version: 4
230
226
  summary: JSON API TOOLKIT
@@ -233,38 +229,31 @@ test_files:
233
229
  - test/lib/jat/config_test.rb
234
230
  - test/lib/jat/plugins/_activerecord_preloads/_activerecord_preloads_test.rb
235
231
  - test/lib/jat/plugins/_activerecord_preloads/lib/preloader_test.rb
236
- - test/lib/jat/plugins/_json_api_activerecord/_json_api_activerecord_test.rb
237
- - test/lib/jat/plugins/_json_api_activerecord/lib/preloads_test.rb
232
+ - test/lib/jat/plugins/_camel_lower/_camel_lower_test.rb
238
233
  - test/lib/jat/plugins/_preloads/_preloads_test.rb
239
234
  - test/lib/jat/plugins/_preloads/lib/format_user_preloads_test.rb
240
235
  - test/lib/jat/plugins/_preloads/lib/preloads_with_path_test.rb
241
236
  - test/lib/jat/plugins/cache/cache_test.rb
242
- - test/lib/jat/plugins/camel_lower/camel_lower_test.rb
243
237
  - test/lib/jat/plugins/json_api/json_api_test.rb
244
- - test/lib/jat/plugins/json_api/lib/construct_traversal_map_test.rb
238
+ - test/lib/jat/plugins/json_api/lib/fields_param_parser_test.rb
239
+ - test/lib/jat/plugins/json_api/lib/include_param_parser_test.rb
245
240
  - test/lib/jat/plugins/json_api/lib/map_test.rb
246
- - test/lib/jat/plugins/json_api/lib/params/fields/parse_test.rb
247
- - test/lib/jat/plugins/json_api/lib/params/fields/validate_test.rb
248
- - test/lib/jat/plugins/json_api/lib/params/fields_test.rb
249
- - test/lib/jat/plugins/json_api/lib/params/include/parse_test.rb
250
- - test/lib/jat/plugins/json_api/lib/params/include/validate_test.rb
251
- - test/lib/jat/plugins/json_api/lib/params/include_test.rb
252
- - test/lib/jat/plugins/json_api/lib/presenters/document_links_presenter_test.rb
253
- - test/lib/jat/plugins/json_api/lib/presenters/document_meta_presenter_test.rb
254
- - test/lib/jat/plugins/json_api/lib/presenters/jsonapi_presenter_test.rb
255
- - test/lib/jat/plugins/json_api/lib/presenters/links_presenter_test.rb
256
- - test/lib/jat/plugins/json_api/lib/presenters/meta_presenter_test.rb
257
- - test/lib/jat/plugins/json_api/lib/presenters/relationship_links_presenter_test.rb
258
- - test/lib/jat/plugins/json_api/lib/presenters/relationship_meta_presenter_test.rb
259
241
  - test/lib/jat/plugins/json_api/lib/response_test.rb
260
- - test/lib/jat/plugins/json_api/lib/traversal_map_test.rb
261
- - test/lib/jat/plugins/simple_api/lib/construct_traversal_map_test.rb
242
+ - test/lib/jat/plugins/json_api_activerecord/json_api_activerecord_test.rb
243
+ - test/lib/jat/plugins/json_api_activerecord/lib/preloads_test.rb
244
+ - test/lib/jat/plugins/json_api_camel_lower/json_api_camel_lower_test.rb
245
+ - test/lib/jat/plugins/json_api_maps_cache/json_api_maps_cache_test.rb
246
+ - test/lib/jat/plugins/json_api_validate_params/json_api_validate_params_test.rb
247
+ - test/lib/jat/plugins/simple_api/lib/fields_param_parser_test.rb
262
248
  - test/lib/jat/plugins/simple_api/lib/map_test.rb
263
- - test/lib/jat/plugins/simple_api/lib/params/parse_test.rb
264
249
  - test/lib/jat/plugins/simple_api/lib/response_test.rb
265
250
  - test/lib/jat/plugins/simple_api/simple_api_test.rb
251
+ - test/lib/jat/plugins/simple_api_activerecord/lib/preloads_test.rb
252
+ - test/lib/jat/plugins/simple_api_activerecord/simple_api_activerecord_test.rb
253
+ - test/lib/jat/plugins/simple_api_camel_lower/simple_api_camel_lower_test.rb
254
+ - test/lib/jat/plugins/simple_api_maps_cache/simple_api_maps_cache_test.rb
255
+ - test/lib/jat/plugins/simple_api_validate_params/simple_api_validate_params_test.rb
266
256
  - test/lib/jat/plugins/to_str/to_str_test.rb
267
- - test/lib/jat/presenter_test.rb
268
257
  - test/lib/jat/utils/enum_deep_dup_test.rb
269
258
  - test/lib/jat/utils/enum_deep_freeze_test.rb
270
259
  - test/lib/jat_test.rb
data/CHANGELOG.md DELETED
@@ -1,7 +0,0 @@
1
- ### Development
2
-
3
- * Replace `.id` DSL method with `.attribute(:id)`
4
- * Allow to add attributes with name `:type`
5
- * Remove possibility to add presenters methods in serializer
6
- * Remove `delegate` option
7
-
data/README.md DELETED
@@ -1,21 +0,0 @@
1
- # JAT (JSON API TOOLKIT)
2
-
3
- JAT helps to serialize complex nested objects to JSON format.
4
-
5
- Key features:
6
-
7
- * **Auto preload** – No need to preload data manually to omit N+1 (Active Record only)
8
- * **Configurable exposed attributes** – No more tons of serializers with different attributes sets
9
- * **Modular design** – plugin system (aka [shrine]) allows you to load only the functionality you need
10
-
11
- ## Output Format
12
-
13
- Supported two serialization formats:
14
- - [JSON:API]
15
- - Simple nested JSON objects (same as good old [AMS] or [Jbuilder])
16
-
17
-
18
- [shrine]: https://shrinerb.com/docs/getting-started#plugin-system
19
- [JSON:API]: https://jsonapi.org/format/
20
- [AMS]: https://github.com/rails-api/active_model_serializers/tree/0-9-stable
21
- [Jbuilder]: https://github.com/rails/jbuilder
data/jat.gemspec DELETED
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Gem::Specification.new do |gem|
4
- gem.name = "jat"
5
- gem.version = "0.0.3"
6
- gem.summary = "JSON API TOOLKIT"
7
- gem.description = <<~DESC
8
- The JAT serializer allows you to generate a JSON response based on the fields requested by the client.
9
- Besides, it avoids manually adding includes and solves N+1 problems on its own.
10
- DESC
11
-
12
- gem.authors = ["Andrey Glushkov"]
13
- gem.email = "aglushkov@shakuro.com"
14
- gem.files = Dir["README.md", "LICENSE.txt", "CHANGELOG.md", "lib/**/*.rb", "jat.gemspec", "doc/**/*.md"]
15
- gem.test_files = `git ls-files -- test/*`.split("\n")
16
- gem.homepage = "https://github.com/aglushkov/jat"
17
- gem.license = "MIT"
18
- gem.required_ruby_version = 2.5
19
- gem.metadata = {
20
- "bug_tracker_uri" => "https://github.com/aglushkov/jat/issues",
21
- "changelog_uri" => "https://github.com/aglushkov/jat/blob/master/CHANGELOG.md",
22
- "source_code_uri" => "https://github.com/aglushkov/jat"
23
- }
24
-
25
- # General testing helpers
26
- gem.add_development_dependency "minitest", "~> 5.14"
27
- gem.add_development_dependency "mocha", "~> 1.12"
28
- gem.add_development_dependency "rake", "~> 13.0"
29
-
30
- # Code standard
31
- gem.add_development_dependency "standard", "~> 1.0"
32
- gem.add_development_dependency "simplecov", "~> 0.21"
33
-
34
- # ORM plugins
35
- gem.add_development_dependency "activerecord", RUBY_VERSION >= "2.5" ? "~> 6.0" : "~> 5.2"
36
- gem.add_development_dependency "sqlite3", "~> 1.4" unless RUBY_ENGINE == "jruby"
37
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "./lib/preloads"
4
-
5
- class Jat
6
- module Plugins
7
- module JsonApiActiverecord
8
- def self.after_load(jat_class, **opts)
9
- jat_class.plugin :_preloads, **opts
10
- jat_class.plugin :_activerecord_preloads, **opts
11
- end
12
-
13
- module ClassMethods
14
- def jat_preloads(jat)
15
- Preloads.call(jat)
16
- end
17
- end
18
- end
19
-
20
- register_plugin(:_json_api_activerecord, JsonApiActiverecord)
21
- end
22
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Jat
4
- module Plugins
5
- module CamelLower
6
- module AttributeMethods
7
- def name
8
- first_word, *other = original_name.to_s.split("_")
9
- last_words = other.map!(&:capitalize).join
10
-
11
- :"#{first_word}#{last_words}"
12
- end
13
- end
14
- end
15
-
16
- register_plugin(:camel_lower, CamelLower)
17
- end
18
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ##
4
- # Combines all serializer and its realtions exposed fields into one hash.
5
- # Returns Hash
6
- # {
7
- # type1 => {
8
- # serializer: ser1,
9
- # attributes: [attr1, attr2, ...],
10
- # relationships: [attr1, attr2, ...]
11
- # },
12
- #
13
- class Jat
14
- module Plugins
15
- module JsonApi
16
- class ConstructTraversalMap
17
- attr_reader :jat_class, :result, :exposed, :manually_exposed
18
-
19
- EXPOSED_VALUES = {all: :all, exposed: :exposed, manual: :manual}.freeze
20
-
21
- def initialize(jat_class, exposed, manually_exposed: {})
22
- @jat_class = jat_class
23
- @exposed = EXPOSED_VALUES.fetch(exposed)
24
- @manually_exposed = manually_exposed
25
- end
26
-
27
- def to_h
28
- @result = {}
29
- append(jat_class)
30
- result
31
- end
32
-
33
- private
34
-
35
- def append(jat_class)
36
- type = jat_class.type
37
- return result if result.key?(type)
38
-
39
- result[type] = {
40
- serializer: jat_class,
41
- attributes: [],
42
- relationships: []
43
- }
44
-
45
- fill(jat_class)
46
- end
47
-
48
- def fill(jat_class)
49
- type = jat_class.type
50
- type_result = result[type]
51
-
52
- jat_class.attributes.each_value do |attribute|
53
- next unless expose?(type, attribute)
54
-
55
- fill_attr(type_result, attribute)
56
- end
57
- end
58
-
59
- def fill_attr(type_result, attribute)
60
- name = attribute.name
61
-
62
- if attribute.relation?
63
- type_result[:relationships] << name
64
- append(attribute.serializer.call)
65
- else
66
- type_result[:attributes] << name
67
- end
68
- end
69
-
70
- def expose?(type, attribute)
71
- return false if attribute.name == :id
72
-
73
- case exposed
74
- when :all then true
75
- when :manual then manually_exposed?(type, attribute)
76
- else attribute.exposed? || manually_exposed?(type, attribute)
77
- end
78
- end
79
-
80
- # Return `attribute.exposed?` when type is not provided
81
- # Checks type is in exposed attributes
82
- def manually_exposed?(type, attribute)
83
- return attribute.exposed? unless manually_exposed.key?(type)
84
-
85
- exposed_attrs = manually_exposed[type]
86
- exposed_attrs.include?(attribute.name)
87
- end
88
- end
89
- end
90
- end
91
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Jat
4
- module Presenters
5
- class DocumentLinksPresenter
6
- module InstanceMethods
7
- # Presented object
8
- attr_reader :object
9
-
10
- # Presented context
11
- attr_reader :context
12
-
13
- def initialize(object, context)
14
- @object = object
15
- @context = context
16
- end
17
- end
18
-
19
- module ClassMethods
20
- attr_accessor :jat_class
21
-
22
- def inspect
23
- "#{jat_class.inspect}::Presenters::DocumentLinksPresenter"
24
- end
25
-
26
- def add_method(name, block)
27
- # Warning-free method redefinition
28
- remove_method(name) if method_defined?(name, false)
29
- define_method(name, &block_without_args(block))
30
- end
31
-
32
- private
33
-
34
- def block_without_args(block)
35
- case block.parameters.count
36
- when 0 then block
37
- when 1 then -> { instance_exec(object, &block) }
38
- when 2 then -> { instance_exec(object, context, &block) }
39
- else raise Error, "Invalid block arguments count"
40
- end
41
- end
42
- end
43
-
44
- extend ClassMethods
45
- include InstanceMethods
46
- end
47
- end
48
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Jat
4
- module Presenters
5
- class DocumentMetaPresenter
6
- module InstanceMethods
7
- # Presented object
8
- attr_reader :object
9
-
10
- # Presented context
11
- attr_reader :context
12
-
13
- def initialize(object, context)
14
- @object = object
15
- @context = context
16
- end
17
- end
18
-
19
- module ClassMethods
20
- attr_accessor :jat_class
21
-
22
- def inspect
23
- "#{jat_class.inspect}::Presenters::DocumentMetaPresenter"
24
- end
25
-
26
- def add_method(name, block)
27
- # Warning-free method redefinition
28
- remove_method(name) if method_defined?(name, false)
29
- define_method(name, &block_without_args(block))
30
- end
31
-
32
- private
33
-
34
- def block_without_args(block)
35
- case block.parameters.count
36
- when 0 then block
37
- when 1 then -> { instance_exec(object, &block) }
38
- when 2 then -> { instance_exec(object, context, &block) }
39
- else raise Error, "Invalid block arguments count"
40
- end
41
- end
42
- end
43
-
44
- extend ClassMethods
45
- include InstanceMethods
46
- end
47
- end
48
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Jat
4
- module Presenters
5
- class JsonapiPresenter
6
- module InstanceMethods
7
- # Presented object
8
- attr_reader :object
9
-
10
- # Presented context
11
- attr_reader :context
12
-
13
- def initialize(object, context)
14
- @object = object
15
- @context = context
16
- end
17
- end
18
-
19
- module ClassMethods
20
- attr_accessor :jat_class
21
-
22
- def inspect
23
- "#{jat_class.inspect}::Presenters::JsonapiPresenter"
24
- end
25
-
26
- def add_method(name, block)
27
- # Warning-free method redefinition
28
- remove_method(name) if method_defined?(name, false)
29
- define_method(name, &block_without_args(block))
30
- end
31
-
32
- private
33
-
34
- def block_without_args(block)
35
- case block.parameters.count
36
- when 0 then block
37
- when 1 then -> { instance_exec(object, &block) }
38
- when 2 then -> { instance_exec(object, context, &block) }
39
- else raise Error, "Invalid block arguments count"
40
- end
41
- end
42
- end
43
-
44
- extend ClassMethods
45
- include InstanceMethods
46
- end
47
- end
48
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Jat
4
- module Presenters
5
- class LinksPresenter
6
- module InstanceMethods
7
- # Presented object
8
- attr_reader :object
9
-
10
- # Presented context
11
- attr_reader :context
12
-
13
- def initialize(object, context)
14
- @object = object
15
- @context = context
16
- end
17
- end
18
-
19
- module ClassMethods
20
- attr_accessor :jat_class
21
-
22
- def inspect
23
- "#{jat_class.inspect}::Presenters::LinksPresenter"
24
- end
25
-
26
- def add_method(name, block)
27
- # Warning-free method redefinition
28
- remove_method(name) if method_defined?(name, false)
29
- define_method(name, &block_without_args(block))
30
- end
31
-
32
- private
33
-
34
- def block_without_args(block)
35
- case block.parameters.count
36
- when 0 then block
37
- when 1 then -> { instance_exec(object, &block) }
38
- when 2 then -> { instance_exec(object, context, &block) }
39
- else raise Error, "Invalid block arguments count"
40
- end
41
- end
42
- end
43
-
44
- extend ClassMethods
45
- include InstanceMethods
46
- end
47
- end
48
- end