yaks 0.4.2 → 0.4.3

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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +65 -5
  4. data/README.md +38 -8
  5. data/Rakefile +33 -0
  6. data/lib/yaks/breaking_changes.rb +22 -0
  7. data/lib/yaks/collection_mapper.rb +18 -21
  8. data/lib/yaks/collection_resource.rb +19 -5
  9. data/lib/yaks/config/dsl.rb +78 -0
  10. data/lib/yaks/config.rb +37 -63
  11. data/lib/yaks/default_policy.rb +27 -9
  12. data/lib/yaks/{serializer → format}/collection_json.rb +7 -3
  13. data/lib/yaks/{serializer → format}/hal.rb +14 -4
  14. data/lib/yaks/{serializer → format}/json_api.rb +22 -4
  15. data/lib/yaks/{serializer.rb → format.rb} +5 -5
  16. data/lib/yaks/fp/hash_updatable.rb +17 -0
  17. data/lib/yaks/fp/updatable.rb +15 -0
  18. data/lib/yaks/mapper/association.rb +24 -21
  19. data/lib/yaks/mapper/association_mapper.rb +42 -0
  20. data/lib/yaks/mapper/attribute.rb +17 -0
  21. data/lib/yaks/mapper/class_methods.rb +0 -1
  22. data/lib/yaks/mapper/config.rb +8 -28
  23. data/lib/yaks/mapper/has_many.rb +8 -3
  24. data/lib/yaks/mapper/has_one.rb +1 -1
  25. data/lib/yaks/mapper/link.rb +13 -13
  26. data/lib/yaks/mapper.rb +28 -32
  27. data/lib/yaks/null_resource.rb +1 -0
  28. data/lib/yaks/resource.rb +15 -5
  29. data/lib/yaks/version.rb +1 -1
  30. data/lib/yaks.rb +16 -10
  31. data/spec/acceptance/acceptance_spec.rb +16 -17
  32. data/spec/acceptance/json_shared_examples.rb +8 -0
  33. data/spec/acceptance/models.rb +2 -2
  34. data/spec/integration/map_to_resource_spec.rb +3 -3
  35. data/spec/json/confucius.collection.json +39 -0
  36. data/spec/json/confucius.hal.json +7 -4
  37. data/spec/json/confucius.json_api.json +1 -1
  38. data/spec/spec_helper.rb +6 -0
  39. data/spec/support/classes_for_policy_testing.rb +36 -0
  40. data/spec/support/shared_contexts.rb +1 -1
  41. data/spec/unit/yaks/collection_mapper_spec.rb +34 -9
  42. data/spec/unit/yaks/collection_resource_spec.rb +4 -4
  43. data/spec/unit/yaks/config/dsl_spec.rb +91 -0
  44. data/spec/unit/yaks/config_spec.rb +10 -6
  45. data/spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb +80 -0
  46. data/spec/unit/yaks/default_policy_spec.rb +50 -0
  47. data/spec/unit/yaks/{serializer → format}/hal_spec.rb +1 -1
  48. data/spec/unit/yaks/format/json_api_spec.rb +42 -0
  49. data/spec/unit/yaks/format_spec.rb +12 -0
  50. data/spec/unit/yaks/fp/hash_updatable_spec.rb +22 -0
  51. data/spec/unit/yaks/fp/updatable_spec.rb +22 -0
  52. data/spec/unit/yaks/mapper/association_mapper_spec.rb +60 -0
  53. data/spec/unit/yaks/mapper/association_spec.rb +96 -41
  54. data/spec/unit/yaks/mapper/attribute_spec.rb +20 -0
  55. data/spec/unit/yaks/mapper/class_methods_spec.rb +49 -10
  56. data/spec/unit/yaks/mapper/config_spec.rb +25 -50
  57. data/spec/unit/yaks/mapper/has_many_spec.rb +33 -5
  58. data/spec/unit/yaks/mapper/has_one_spec.rb +32 -17
  59. data/spec/unit/yaks/mapper/link_spec.rb +44 -12
  60. data/spec/unit/yaks/mapper_spec.rb +45 -17
  61. data/spec/unit/yaks/resource_spec.rb +41 -7
  62. data/yaks.gemspec +7 -1
  63. metadata +72 -21
  64. data/examples/hal01.rb +0 -126
  65. data/examples/jsonapi01.rb +0 -68
  66. data/examples/jsonapi02.rb +0 -62
  67. data/examples/jsonapi03.rb +0 -86
  68. data/spec/support/serializers.rb +0 -14
  69. data/spec/unit/yaks/serializer_spec.rb +0 -12
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arne Brasseur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-24 00:00:00.000000000 Z
11
+ date: 2014-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflection
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '2.99'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bogus
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -126,16 +140,16 @@ dependencies:
126
140
  name: mutant
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
- - - '='
143
+ - - ">="
130
144
  - !ruby/object:Gem::Version
131
- version: 0.5.12
145
+ version: '0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
- - - '='
150
+ - - ">="
137
151
  - !ruby/object:Gem::Version
138
- version: 0.5.12
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rspec-its
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -182,18 +196,24 @@ files:
182
196
  - README.md
183
197
  - Rakefile
184
198
  - bench/bench.rb
185
- - examples/hal01.rb
186
- - examples/jsonapi01.rb
187
- - examples/jsonapi02.rb
188
- - examples/jsonapi03.rb
189
199
  - lib/yaks.rb
200
+ - lib/yaks/breaking_changes.rb
190
201
  - lib/yaks/collection_mapper.rb
191
202
  - lib/yaks/collection_resource.rb
192
203
  - lib/yaks/config.rb
204
+ - lib/yaks/config/dsl.rb
193
205
  - lib/yaks/default_policy.rb
206
+ - lib/yaks/format.rb
207
+ - lib/yaks/format/collection_json.rb
208
+ - lib/yaks/format/hal.rb
209
+ - lib/yaks/format/json_api.rb
194
210
  - lib/yaks/fp.rb
211
+ - lib/yaks/fp/hash_updatable.rb
212
+ - lib/yaks/fp/updatable.rb
195
213
  - lib/yaks/mapper.rb
196
214
  - lib/yaks/mapper/association.rb
215
+ - lib/yaks/mapper/association_mapper.rb
216
+ - lib/yaks/mapper/attribute.rb
197
217
  - lib/yaks/mapper/class_methods.rb
198
218
  - lib/yaks/mapper/config.rb
199
219
  - lib/yaks/mapper/has_many.rb
@@ -203,38 +223,46 @@ files:
203
223
  - lib/yaks/primitivize.rb
204
224
  - lib/yaks/resource.rb
205
225
  - lib/yaks/resource/link.rb
206
- - lib/yaks/serializer.rb
207
- - lib/yaks/serializer/collection_json.rb
208
- - lib/yaks/serializer/hal.rb
209
- - lib/yaks/serializer/json_api.rb
210
226
  - lib/yaks/util.rb
211
227
  - lib/yaks/version.rb
212
228
  - notes.org
213
229
  - shaved_yak.gif
214
230
  - spec/acceptance/acceptance_spec.rb
231
+ - spec/acceptance/json_shared_examples.rb
215
232
  - spec/acceptance/models.rb
216
233
  - spec/fixture_helpers.rb
217
234
  - spec/integration/map_to_resource_spec.rb
235
+ - spec/json/confucius.collection.json
218
236
  - spec/json/confucius.hal.json
219
237
  - spec/json/confucius.json_api.json
220
238
  - spec/json/hal_plant_collection.json
221
239
  - spec/json/john.hal.json
222
240
  - spec/json/youtypeitwepostit.collection.json
223
241
  - spec/spec_helper.rb
242
+ - spec/support/classes_for_policy_testing.rb
224
243
  - spec/support/deep_eql.rb
225
244
  - spec/support/fixtures.rb
226
245
  - spec/support/friends_mapper.rb
227
246
  - spec/support/models.rb
228
247
  - spec/support/pet_mapper.rb
229
248
  - spec/support/pet_peeve_mapper.rb
230
- - spec/support/serializers.rb
231
249
  - spec/support/shared_contexts.rb
232
250
  - spec/support/youtypeit_models_mappers.rb
233
251
  - spec/unit/yaks/collection_mapper_spec.rb
234
252
  - spec/unit/yaks/collection_resource_spec.rb
253
+ - spec/unit/yaks/config/dsl_spec.rb
235
254
  - spec/unit/yaks/config_spec.rb
255
+ - spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb
256
+ - spec/unit/yaks/default_policy_spec.rb
257
+ - spec/unit/yaks/format/hal_spec.rb
258
+ - spec/unit/yaks/format/json_api_spec.rb
259
+ - spec/unit/yaks/format_spec.rb
260
+ - spec/unit/yaks/fp/hash_updatable_spec.rb
261
+ - spec/unit/yaks/fp/updatable_spec.rb
236
262
  - spec/unit/yaks/fp_spec.rb
263
+ - spec/unit/yaks/mapper/association_mapper_spec.rb
237
264
  - spec/unit/yaks/mapper/association_spec.rb
265
+ - spec/unit/yaks/mapper/attribute_spec.rb
238
266
  - spec/unit/yaks/mapper/class_methods_spec.rb
239
267
  - spec/unit/yaks/mapper/config_spec.rb
240
268
  - spec/unit/yaks/mapper/has_many_spec.rb
@@ -245,8 +273,6 @@ files:
245
273
  - spec/unit/yaks/primitivize_spec.rb
246
274
  - spec/unit/yaks/resource/link_spec.rb
247
275
  - spec/unit/yaks/resource_spec.rb
248
- - spec/unit/yaks/serializer/hal_spec.rb
249
- - spec/unit/yaks/serializer_spec.rb
250
276
  - spec/unit/yaks/util_spec.rb
251
277
  - spec/yaml/confucius.yaml
252
278
  - spec/yaml/youtypeitwepostit.yaml
@@ -255,7 +281,22 @@ homepage: https://github.com/plexus/yaks
255
281
  licenses:
256
282
  - MIT
257
283
  metadata: {}
258
- post_install_message:
284
+ post_install_message: |2+
285
+
286
+
287
+ Breaking Changes in Yaks 0.4.3
288
+ ==============================
289
+
290
+ Yaks::Mapper#filter was removed, if you override this method in your
291
+ mappers to conditionally filter attributes or associations, you will
292
+ have to override #attributes or #associations instead.
293
+
294
+ When specifying a rel_template, now a single {rel} placeholder is
295
+ expected instead of {src} and {dest}.
296
+
297
+ There are other internal changes. See the CHANGELOG and README for full
298
+ documentation.
299
+
259
300
  rdoc_options: []
260
301
  require_paths:
261
302
  - lib
@@ -277,29 +318,41 @@ specification_version: 4
277
318
  summary: Serialize to hypermedia. HAL, JSON-API, etc.
278
319
  test_files:
279
320
  - spec/acceptance/acceptance_spec.rb
321
+ - spec/acceptance/json_shared_examples.rb
280
322
  - spec/acceptance/models.rb
281
323
  - spec/fixture_helpers.rb
282
324
  - spec/integration/map_to_resource_spec.rb
325
+ - spec/json/confucius.collection.json
283
326
  - spec/json/confucius.hal.json
284
327
  - spec/json/confucius.json_api.json
285
328
  - spec/json/hal_plant_collection.json
286
329
  - spec/json/john.hal.json
287
330
  - spec/json/youtypeitwepostit.collection.json
288
331
  - spec/spec_helper.rb
332
+ - spec/support/classes_for_policy_testing.rb
289
333
  - spec/support/deep_eql.rb
290
334
  - spec/support/fixtures.rb
291
335
  - spec/support/friends_mapper.rb
292
336
  - spec/support/models.rb
293
337
  - spec/support/pet_mapper.rb
294
338
  - spec/support/pet_peeve_mapper.rb
295
- - spec/support/serializers.rb
296
339
  - spec/support/shared_contexts.rb
297
340
  - spec/support/youtypeit_models_mappers.rb
298
341
  - spec/unit/yaks/collection_mapper_spec.rb
299
342
  - spec/unit/yaks/collection_resource_spec.rb
343
+ - spec/unit/yaks/config/dsl_spec.rb
300
344
  - spec/unit/yaks/config_spec.rb
345
+ - spec/unit/yaks/default_policy/derive_mapper_from_object_spec.rb
346
+ - spec/unit/yaks/default_policy_spec.rb
347
+ - spec/unit/yaks/format/hal_spec.rb
348
+ - spec/unit/yaks/format/json_api_spec.rb
349
+ - spec/unit/yaks/format_spec.rb
350
+ - spec/unit/yaks/fp/hash_updatable_spec.rb
351
+ - spec/unit/yaks/fp/updatable_spec.rb
301
352
  - spec/unit/yaks/fp_spec.rb
353
+ - spec/unit/yaks/mapper/association_mapper_spec.rb
302
354
  - spec/unit/yaks/mapper/association_spec.rb
355
+ - spec/unit/yaks/mapper/attribute_spec.rb
303
356
  - spec/unit/yaks/mapper/class_methods_spec.rb
304
357
  - spec/unit/yaks/mapper/config_spec.rb
305
358
  - spec/unit/yaks/mapper/has_many_spec.rb
@@ -310,8 +363,6 @@ test_files:
310
363
  - spec/unit/yaks/primitivize_spec.rb
311
364
  - spec/unit/yaks/resource/link_spec.rb
312
365
  - spec/unit/yaks/resource_spec.rb
313
- - spec/unit/yaks/serializer/hal_spec.rb
314
- - spec/unit/yaks/serializer_spec.rb
315
366
  - spec/unit/yaks/util_spec.rb
316
367
  - spec/yaml/confucius.yaml
317
368
  - spec/yaml/youtypeitwepostit.yaml
data/examples/hal01.rb DELETED
@@ -1,126 +0,0 @@
1
- # http://stateless.co/hal_specification.html
2
-
3
- # There are still some affordances missing to support all of HAL, in particular
4
- # for this example to ability to generate links based on composite content
5
- # (ea:admin) is not implemented, neither is explicit support for CURIEs (compact
6
- # URI shorthand syntax), although this examples works around that by manually
7
- # encoding the CURIE prefixes.
8
-
9
- # The 'next' link from the example below is also ommitted, pagination is an aspect
10
- # that will be implemented generically
11
-
12
- # Example from the specification, approximated with Yaks below
13
-
14
- # {
15
- # "_links": {
16
- # "self": { "href": "/orders" },
17
- # "curies": [{ "name": "ea", "href": "http://example.com/docs/rels/{rel}", "templated": true }],
18
- # "next": { "href": "/orders?page=2" },
19
- # "ea:find": { "href": "/orders{?id}", "templated": true },
20
- # "ea:admin": [{
21
- # "href": "/admins/2",
22
- # "title": "Fred"
23
- # }, {
24
- # "href": "/admins/5",
25
- # "title": "Kate"
26
- # }]
27
- # },
28
- # "currentlyProcessing": 14,
29
- # "shippedToday": 20,
30
- # "_embedded": {
31
- # "ea:order": [{
32
- # "_links": {
33
- # "self": { "href": "/orders/123" },
34
- # "ea:basket": { "href": "/baskets/98712" },
35
- # "ea:customer": { "href": "/customers/7809" }
36
- # },
37
- # "total": 30.00,
38
- # "currency": "USD",
39
- # "status": "shipped"
40
- # }, {
41
- # "_links": {
42
- # "self": { "href": "/orders/124" },
43
- # "ea:basket": { "href": "/baskets/97213" },
44
- # "ea:customer": { "href": "/customers/12369" }
45
- # },
46
- # "total": 20.00,
47
- # "currency": "USD",
48
- # "status": "processing"
49
- # }]
50
- # }
51
- # }
52
-
53
- require 'virtus'
54
- require 'yaks'
55
- require 'json'
56
-
57
- class Order
58
- include Virtus.model
59
- attribute :id, Integer
60
- attribute :basket_id, Integer
61
- attribute :customer_id, Integer
62
- attribute :total, Numeric
63
- attribute :currency, String
64
- attribute :status, String
65
- end
66
-
67
- class OrderSet
68
- include Virtus.model
69
- attribute :currently_processing, Integer
70
- attribute :shipped_today, Integer
71
- attribute :orders, Array[Order]
72
- end
73
-
74
- class OrderMapper < Yaks::Mapper
75
- link :self, '/orders/{id}'
76
- link :"ea:basket", '/baskets/{basket_id}'
77
- link :"ea:customer", '/customers/{customer_id}'
78
-
79
- attributes :total, :currency, :status
80
- end
81
-
82
- class OrderSetMapper < Yaks::Mapper
83
- link :self, '/orders'
84
- link :curies, 'http://example.com/docs/rels/{rel}', name: "ea", expand: false
85
- link :"ea:find", "/orders{?id}", expand: false
86
-
87
- attributes :currentlyProcessing, :shippedToday
88
-
89
- has_many :orders, as: :"ea:order", mapper: OrderMapper
90
-
91
- # Having the attributes be encoded in CamelCase is such a common
92
- # use case we might have to make this a setting
93
-
94
- def load_attribute(name)
95
- super(Yaks::Util.underscore(name.to_s))
96
- end
97
- end
98
-
99
- order_set = OrderSet.new(
100
- currently_processing: 14,
101
- shipped_today: 20,
102
- orders: [
103
- Order.new(
104
- id: 123,
105
- basket_id: 98712,
106
- customer_id: 7809,
107
- total: 30.00,
108
- currency: "USD",
109
- status: "shipped"
110
- ),
111
- Order.new(
112
- id: 124,
113
- basket_id: 97213,
114
- customer_id: 12369,
115
- total: 20.00,
116
- currency: "USD",
117
- status: "processing"
118
- )
119
- ]
120
- )
121
-
122
- resource = OrderSetMapper.new(order_set).to_resource
123
-
124
- hal = Yaks::HalSerializer.new(resource, singular_links: [:self, :"ea:find", :"ea:basket", :"ea:customer"]).to_hal
125
-
126
- puts JSON.dump(hal)
@@ -1,68 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require 'virtus'
4
- require 'yaks'
5
- require 'json'
6
-
7
- Example = JSON.parse %q<
8
- {
9
- "posts": [{
10
- "id": "1",
11
- "title": "Rails is Omakase",
12
- "links": {
13
- "author": "9",
14
- "comments": [ "5", "12", "17", "20" ]
15
- }
16
- }]
17
- }
18
- >
19
-
20
- class Author
21
- include Virtus.model
22
- attribute :id, String
23
- end
24
-
25
- class Comment
26
- include Virtus.model
27
- attribute :id, String
28
- end
29
-
30
- class Post
31
- include Virtus.model
32
- attribute :id, String
33
- attribute :title, String
34
- attribute :author, Author
35
- attribute :comments, Array[Comment]
36
- end
37
-
38
- class AuthorMapper < Yaks::Mapper
39
- attributes :id
40
- end
41
-
42
- class CommentMapper < Yaks::Mapper
43
- attributes :id
44
- end
45
-
46
- class PostMapper < Yaks::Mapper
47
- attributes :id, :title, :links
48
-
49
- has_one :author, mapper: AuthorMapper
50
- has_many :comments, mapper: CommentMapper
51
- end
52
-
53
- post = Post.new(
54
- id: 1,
55
- title: "Rails is Omakase",
56
- author: Author.new(id: "9"),
57
- comments: [5, 12, 17, 20].map {|id| Comment.new(id: id.to_s)}
58
- )
59
-
60
- resource = PostMapper.new(post).to_resource
61
- json_api = Yaks::JsonApiSerializer.new(resource).to_json_api
62
-
63
- gem 'minitest'
64
- require 'minitest/autorun'
65
-
66
- describe('json-api') {
67
- specify { assert_equal Example, json_api }
68
- }
@@ -1,62 +0,0 @@
1
- require 'virtus'
2
- require 'yaks'
3
- require 'json'
4
-
5
- Example = JSON.parse %q<
6
- {
7
- "posts": [{
8
- "id": "1",
9
- "title": "Rails is Omakase",
10
- "links": {
11
- "author": "9"
12
- }
13
- }],
14
- "linked": {
15
- "people": [{
16
- "id": "9",
17
- "name": "@d2h"
18
- }]
19
- }
20
- }
21
- >
22
-
23
-
24
- class Person
25
- include Virtus.model
26
- attribute :id, String
27
- attribute :name, String
28
- end
29
-
30
- class Post
31
- include Virtus.model
32
- attribute :id, String
33
- attribute :title, String
34
- attribute :author, Person
35
- end
36
-
37
- class PersonMapper < Yaks::Mapper
38
- attributes :id, :name
39
- end
40
-
41
- class PostMapper < Yaks::Mapper
42
- attributes :id, :title, :links
43
-
44
- has_one :author, mapper: PersonMapper
45
- end
46
-
47
- post = Post.new(
48
- id: 1,
49
- title: "Rails is Omakase",
50
- author: Person.new(id: "9", name: "@d2h"),
51
- )
52
-
53
- resource = PostMapper.new(post).to_resource
54
-
55
- json_api = Yaks::JsonApiSerializer.new(resource, embed: :resources).to_json_api
56
-
57
- gem 'minitest'
58
- require 'minitest/autorun'
59
-
60
- describe('json-api') {
61
- specify { assert_equal Example, json_api }
62
- }
@@ -1,86 +0,0 @@
1
- require 'virtus'
2
- require 'yaks'
3
- require 'json'
4
-
5
- Example = JSON.parse %q<
6
- {
7
- "posts": [{
8
- "id": "1",
9
- "title": "Rails is Omakase",
10
- "links": {
11
- "author": "http://example.com/people/1",
12
- "comments": "http://example.com/comments/5,12,17,20"
13
- }
14
- }]
15
- }
16
- >
17
-
18
-
19
- class Person
20
- include Virtus.model
21
- attribute :id, String
22
- attribute :name, String
23
- end
24
-
25
-
26
- class Comment
27
- include Virtus.model
28
- attribute :id, String
29
- end
30
-
31
- class Post
32
- include Virtus.model
33
- attribute :id, String
34
- attribute :title, String
35
- attribute :author, Person
36
- attribute :comments, Array[Comment]
37
- end
38
-
39
- class BaseMapper < Yaks::Mapper
40
- link :self, 'http://example.com/{plural_profile_type}/{id}'
41
-
42
- def plural_profile_type
43
- pluralize(profile_type.to_s)
44
- end
45
- end
46
-
47
- class CollectionMapper < Yaks::CollectionMapper
48
- link :self, 'http://example.com/{plural_profile_type}/{id*}'
49
-
50
- def plural_profile_type
51
- pluralize(profile_type.to_s)
52
- end
53
- end
54
-
55
- class CommentMapper < BaseMapper
56
- attributes :id
57
- end
58
-
59
- class PersonMapper < BaseMapper
60
- attributes :id, :name
61
- end
62
-
63
- class PostMapper < BaseMapper
64
- attributes :id, :title
65
-
66
- has_one :author, mapper: PersonMapper
67
- has_many :comments, mapper: CommentMapper, collection_mapper: CollectionMapper
68
- end
69
-
70
- post = Post.new(
71
- id: 1,
72
- title: "Rails is Omakase",
73
- author: Person.new(id: "1", name: "@d2h"),
74
- comments: [5, 12, 17, 20].map {|id| Comment.new(id: id.to_s)}
75
- )
76
-
77
- resource = PostMapper.new(post).to_resource
78
-
79
- json_api = Yaks::JsonApiSerializer.new(resource, embed: :links).to_json_api
80
-
81
- gem 'minitest'
82
- require 'minitest/autorun'
83
-
84
- describe('json-api') {
85
- specify { assert_equal Example, json_api }
86
- }
@@ -1,14 +0,0 @@
1
- # class FriendSerializer < Yaks::Mapper
2
- # attributes :id, :name
3
-
4
- # has_many :pets
5
- # has_one :pet_peeve
6
- # end
7
-
8
- # class PetSerializer < Yaks::Mapper
9
- # attributes :id, :name, :species
10
- # end
11
-
12
- # class PetPeeveSerializer < Yaks::Mapper
13
- # attributes :id, :type
14
- # end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Yaks::Serializer do
4
- describe '.by_name' do
5
- specify { expect(Yaks::Serializer.by_name(:hal)).to eql Yaks::Serializer::Hal }
6
- specify { expect(Yaks::Serializer.by_name(:json_api)).to eql Yaks::Serializer::JsonApi }
7
- end
8
-
9
- describe '.by_mime_type' do
10
- specify { expect(Yaks::Serializer.by_mime_type('application/hal+json')).to eql Yaks::Serializer::Hal }
11
- end
12
- end