yaks 0.3.1 → 0.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +0 -2
- data/LICENSE +7 -0
- data/README.md +160 -35
- data/Rakefile +2 -1
- data/lib/yaks/collection_mapper.rb +25 -18
- data/lib/yaks/collection_resource.rb +11 -17
- data/lib/yaks/config.rb +96 -0
- data/lib/yaks/default_policy.rb +34 -4
- data/lib/yaks/fp.rb +18 -0
- data/lib/yaks/mapper/association.rb +19 -27
- data/lib/yaks/mapper/class_methods.rb +4 -2
- data/lib/yaks/mapper/config.rb +24 -39
- data/lib/yaks/mapper/has_many.rb +7 -6
- data/lib/yaks/mapper/has_one.rb +4 -3
- data/lib/yaks/mapper/link.rb +52 -55
- data/lib/yaks/mapper.rb +38 -26
- data/lib/yaks/null_resource.rb +3 -3
- data/lib/yaks/primitivize.rb +29 -27
- data/lib/yaks/resource/link.rb +4 -0
- data/lib/yaks/resource.rb +18 -7
- data/lib/yaks/serializer/collection_json.rb +38 -0
- data/lib/yaks/serializer/hal.rb +55 -0
- data/lib/yaks/serializer/json_api.rb +61 -0
- data/lib/yaks/serializer.rb +25 -4
- data/lib/yaks/util.rb +2 -42
- data/lib/yaks/version.rb +1 -1
- data/lib/yaks.rb +10 -32
- data/notes.org +72 -0
- data/shaved_yak.gif +0 -0
- data/spec/acceptance/acceptance_spec.rb +46 -0
- data/spec/acceptance/models.rb +28 -0
- data/spec/integration/map_to_resource_spec.rb +11 -15
- data/spec/json/confucius.hal.json +23 -0
- data/spec/json/confucius.json_api.json +22 -0
- data/spec/json/john.hal.json +29 -0
- data/spec/json/youtypeitwepostit.collection.json +45 -0
- data/spec/spec_helper.rb +12 -1
- data/spec/support/shared_contexts.rb +7 -10
- data/spec/support/youtypeit_models_mappers.rb +20 -0
- data/spec/unit/yaks/collection_mapper_spec.rb +84 -0
- data/spec/unit/yaks/collection_resource_spec.rb +72 -0
- data/spec/unit/yaks/config_spec.rb +129 -0
- data/spec/unit/yaks/fp_spec.rb +31 -0
- data/spec/unit/yaks/mapper/association_spec.rb +80 -0
- data/spec/{yaks → unit/yaks}/mapper/class_methods_spec.rb +4 -4
- data/spec/unit/yaks/mapper/config_spec.rb +191 -0
- data/spec/unit/yaks/mapper/has_many_spec.rb +46 -0
- data/spec/unit/yaks/mapper/has_one_spec.rb +34 -0
- data/spec/unit/yaks/mapper/link_spec.rb +152 -0
- data/spec/unit/yaks/mapper_spec.rb +177 -0
- data/spec/unit/yaks/resource_spec.rb +40 -0
- data/spec/{yaks/hal_serializer_spec.rb → unit/yaks/serializer/hal_spec.rb} +2 -2
- data/spec/unit/yaks/serializer_spec.rb +12 -0
- data/spec/unit/yaks/util_spec.rb +43 -0
- data/spec/yaml/confucius.yaml +10 -0
- data/spec/yaml/youtypeitwepostit.yaml +9 -0
- data/yaks.gemspec +7 -8
- metadata +92 -53
- data/Gemfile.lock +0 -111
- data/lib/yaks/hal_serializer.rb +0 -59
- data/lib/yaks/json_api_serializer.rb +0 -59
- data/lib/yaks/link_lookup.rb +0 -23
- data/lib/yaks/mapper/lookup.rb +0 -19
- data/lib/yaks/mapper/map_links.rb +0 -17
- data/lib/yaks/profile_registry.rb +0 -60
- data/lib/yaks/rel_registry.rb +0 -20
- data/lib/yaks/shared_options.rb +0 -15
- data/spec/support/shorthands.rb +0 -22
- data/spec/yaks/collection_resource_spec.rb +0 -9
- data/spec/yaks/mapper/association_spec.rb +0 -21
- data/spec/yaks/mapper/config_spec.rb +0 -77
- data/spec/yaks/mapper/has_one_spec.rb +0 -16
- data/spec/yaks/mapper/link_spec.rb +0 -38
- data/spec/yaks/mapper/map_links_spec.rb +0 -46
- data/spec/yaks/mapper_spec.rb +0 -65
- data/spec/yaks/resource_spec.rb +0 -23
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0.rc1
|
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-
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: inflection
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '1.0'
|
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: '0'
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: concord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 0.1.4
|
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: 1.
|
40
|
+
version: 0.1.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: uri_template
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.6.0
|
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: 0.
|
54
|
+
version: 0.6.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rack-accept
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.4.5
|
62
62
|
type: :runtime
|
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: 0.
|
68
|
+
version: 0.4.5
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: virtus
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '3.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '3.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rake
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,21 @@ dependencies:
|
|
122
122
|
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec-its
|
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'
|
139
|
+
description: Serialize to hypermedia. HAL, JSON-API, etc.
|
126
140
|
email:
|
127
141
|
- arne@arnebrasseur.net
|
128
142
|
executables: []
|
@@ -134,7 +148,7 @@ files:
|
|
134
148
|
- .travis.yml
|
135
149
|
- CHANGELOG.md
|
136
150
|
- Gemfile
|
137
|
-
-
|
151
|
+
- LICENSE
|
138
152
|
- README.md
|
139
153
|
- Rakefile
|
140
154
|
- examples/hal01.rb
|
@@ -144,10 +158,9 @@ files:
|
|
144
158
|
- lib/yaks.rb
|
145
159
|
- lib/yaks/collection_mapper.rb
|
146
160
|
- lib/yaks/collection_resource.rb
|
161
|
+
- lib/yaks/config.rb
|
147
162
|
- lib/yaks/default_policy.rb
|
148
|
-
- lib/yaks/
|
149
|
-
- lib/yaks/json_api_serializer.rb
|
150
|
-
- lib/yaks/link_lookup.rb
|
163
|
+
- lib/yaks/fp.rb
|
151
164
|
- lib/yaks/mapper.rb
|
152
165
|
- lib/yaks/mapper/association.rb
|
153
166
|
- lib/yaks/mapper/class_methods.rb
|
@@ -155,20 +168,26 @@ files:
|
|
155
168
|
- lib/yaks/mapper/has_many.rb
|
156
169
|
- lib/yaks/mapper/has_one.rb
|
157
170
|
- lib/yaks/mapper/link.rb
|
158
|
-
- lib/yaks/mapper/lookup.rb
|
159
|
-
- lib/yaks/mapper/map_links.rb
|
160
171
|
- lib/yaks/null_resource.rb
|
161
172
|
- lib/yaks/primitivize.rb
|
162
|
-
- lib/yaks/profile_registry.rb
|
163
|
-
- lib/yaks/rel_registry.rb
|
164
173
|
- lib/yaks/resource.rb
|
165
174
|
- lib/yaks/resource/link.rb
|
166
175
|
- lib/yaks/serializer.rb
|
167
|
-
- lib/yaks/
|
176
|
+
- lib/yaks/serializer/collection_json.rb
|
177
|
+
- lib/yaks/serializer/hal.rb
|
178
|
+
- lib/yaks/serializer/json_api.rb
|
168
179
|
- lib/yaks/util.rb
|
169
180
|
- lib/yaks/version.rb
|
181
|
+
- notes.org
|
182
|
+
- shaved_yak.gif
|
183
|
+
- spec/acceptance/acceptance_spec.rb
|
184
|
+
- spec/acceptance/models.rb
|
170
185
|
- spec/integration/map_to_resource_spec.rb
|
186
|
+
- spec/json/confucius.hal.json
|
187
|
+
- spec/json/confucius.json_api.json
|
171
188
|
- spec/json/hal_plant_collection.json
|
189
|
+
- spec/json/john.hal.json
|
190
|
+
- spec/json/youtypeitwepostit.collection.json
|
172
191
|
- spec/spec_helper.rb
|
173
192
|
- spec/support/fixtures.rb
|
174
193
|
- spec/support/friends_mapper.rb
|
@@ -177,17 +196,24 @@ files:
|
|
177
196
|
- spec/support/pet_peeve_mapper.rb
|
178
197
|
- spec/support/serializers.rb
|
179
198
|
- spec/support/shared_contexts.rb
|
180
|
-
- spec/support/
|
181
|
-
- spec/yaks/
|
182
|
-
- spec/yaks/
|
183
|
-
- spec/yaks/
|
184
|
-
- spec/yaks/
|
185
|
-
- spec/yaks/mapper/
|
186
|
-
- spec/yaks/mapper/
|
187
|
-
- spec/yaks/mapper/
|
188
|
-
- spec/yaks/mapper/
|
189
|
-
- spec/yaks/
|
190
|
-
- spec/yaks/
|
199
|
+
- spec/support/youtypeit_models_mappers.rb
|
200
|
+
- spec/unit/yaks/collection_mapper_spec.rb
|
201
|
+
- spec/unit/yaks/collection_resource_spec.rb
|
202
|
+
- spec/unit/yaks/config_spec.rb
|
203
|
+
- spec/unit/yaks/fp_spec.rb
|
204
|
+
- spec/unit/yaks/mapper/association_spec.rb
|
205
|
+
- spec/unit/yaks/mapper/class_methods_spec.rb
|
206
|
+
- spec/unit/yaks/mapper/config_spec.rb
|
207
|
+
- spec/unit/yaks/mapper/has_many_spec.rb
|
208
|
+
- spec/unit/yaks/mapper/has_one_spec.rb
|
209
|
+
- spec/unit/yaks/mapper/link_spec.rb
|
210
|
+
- spec/unit/yaks/mapper_spec.rb
|
211
|
+
- spec/unit/yaks/resource_spec.rb
|
212
|
+
- spec/unit/yaks/serializer/hal_spec.rb
|
213
|
+
- spec/unit/yaks/serializer_spec.rb
|
214
|
+
- spec/unit/yaks/util_spec.rb
|
215
|
+
- spec/yaml/confucius.yaml
|
216
|
+
- spec/yaml/youtypeitwepostit.yaml
|
191
217
|
- yaks.gemspec
|
192
218
|
homepage: https://github.com/plexus/yaks
|
193
219
|
licenses:
|
@@ -204,18 +230,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
204
230
|
version: '0'
|
205
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
232
|
requirements:
|
207
|
-
- - '
|
233
|
+
- - '>'
|
208
234
|
- !ruby/object:Gem::Version
|
209
|
-
version:
|
235
|
+
version: 1.3.1
|
210
236
|
requirements: []
|
211
237
|
rubyforge_project:
|
212
238
|
rubygems_version: 2.2.2
|
213
239
|
signing_key:
|
214
240
|
specification_version: 4
|
215
|
-
summary: Serialize to JSON-API
|
241
|
+
summary: Serialize to hypermedia. HAL, JSON-API, etc.
|
216
242
|
test_files:
|
243
|
+
- spec/acceptance/acceptance_spec.rb
|
244
|
+
- spec/acceptance/models.rb
|
217
245
|
- spec/integration/map_to_resource_spec.rb
|
246
|
+
- spec/json/confucius.hal.json
|
247
|
+
- spec/json/confucius.json_api.json
|
218
248
|
- spec/json/hal_plant_collection.json
|
249
|
+
- spec/json/john.hal.json
|
250
|
+
- spec/json/youtypeitwepostit.collection.json
|
219
251
|
- spec/spec_helper.rb
|
220
252
|
- spec/support/fixtures.rb
|
221
253
|
- spec/support/friends_mapper.rb
|
@@ -224,14 +256,21 @@ test_files:
|
|
224
256
|
- spec/support/pet_peeve_mapper.rb
|
225
257
|
- spec/support/serializers.rb
|
226
258
|
- spec/support/shared_contexts.rb
|
227
|
-
- spec/support/
|
228
|
-
- spec/yaks/
|
229
|
-
- spec/yaks/
|
230
|
-
- spec/yaks/
|
231
|
-
- spec/yaks/
|
232
|
-
- spec/yaks/mapper/
|
233
|
-
- spec/yaks/mapper/
|
234
|
-
- spec/yaks/mapper/
|
235
|
-
- spec/yaks/mapper/
|
236
|
-
- spec/yaks/
|
237
|
-
- spec/yaks/
|
259
|
+
- spec/support/youtypeit_models_mappers.rb
|
260
|
+
- spec/unit/yaks/collection_mapper_spec.rb
|
261
|
+
- spec/unit/yaks/collection_resource_spec.rb
|
262
|
+
- spec/unit/yaks/config_spec.rb
|
263
|
+
- spec/unit/yaks/fp_spec.rb
|
264
|
+
- spec/unit/yaks/mapper/association_spec.rb
|
265
|
+
- spec/unit/yaks/mapper/class_methods_spec.rb
|
266
|
+
- spec/unit/yaks/mapper/config_spec.rb
|
267
|
+
- spec/unit/yaks/mapper/has_many_spec.rb
|
268
|
+
- spec/unit/yaks/mapper/has_one_spec.rb
|
269
|
+
- spec/unit/yaks/mapper/link_spec.rb
|
270
|
+
- spec/unit/yaks/mapper_spec.rb
|
271
|
+
- spec/unit/yaks/resource_spec.rb
|
272
|
+
- spec/unit/yaks/serializer/hal_spec.rb
|
273
|
+
- spec/unit/yaks/serializer_spec.rb
|
274
|
+
- spec/unit/yaks/util_spec.rb
|
275
|
+
- spec/yaml/confucius.yaml
|
276
|
+
- spec/yaml/youtypeitwepostit.yaml
|
data/Gemfile.lock
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
GIT
|
2
|
-
remote: git://github.com/harukizaemon/hamster.git
|
3
|
-
revision: f34f3e2faa489818bbbd069acaec005692891bc6
|
4
|
-
specs:
|
5
|
-
hamster (1.0.1.pre.rc.1)
|
6
|
-
|
7
|
-
PATH
|
8
|
-
remote: .
|
9
|
-
specs:
|
10
|
-
yaks (0.3.1)
|
11
|
-
concord (~> 0.1.4)
|
12
|
-
hamster
|
13
|
-
inflection (~> 1.0.0)
|
14
|
-
uri_template (~> 0.6.0)
|
15
|
-
|
16
|
-
GEM
|
17
|
-
remote: https://rubygems.org/
|
18
|
-
specs:
|
19
|
-
abstract_type (0.0.7)
|
20
|
-
adamantium (0.2.0)
|
21
|
-
ice_nine (~> 0.11.0)
|
22
|
-
memoizable (~> 0.4.0)
|
23
|
-
anima (0.2.0)
|
24
|
-
abstract_type (~> 0.0.7)
|
25
|
-
adamantium (~> 0.1)
|
26
|
-
equalizer (~> 0.0.8)
|
27
|
-
ast (2.0.0)
|
28
|
-
axiom-types (0.1.1)
|
29
|
-
descendants_tracker (~> 0.0.4)
|
30
|
-
ice_nine (~> 0.11.0)
|
31
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
32
|
-
coercible (1.0.0)
|
33
|
-
descendants_tracker (~> 0.0.1)
|
34
|
-
concord (0.1.5)
|
35
|
-
adamantium (~> 0.2.0)
|
36
|
-
equalizer (~> 0.0.9)
|
37
|
-
descendants_tracker (0.0.4)
|
38
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
39
|
-
diff-lcs (1.2.5)
|
40
|
-
equalizer (0.0.9)
|
41
|
-
ice_nine (0.11.0)
|
42
|
-
inflection (1.0.0)
|
43
|
-
inflecto (0.0.2)
|
44
|
-
memoizable (0.4.2)
|
45
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
46
|
-
morpher (0.2.3)
|
47
|
-
abstract_type (~> 0.0.7)
|
48
|
-
adamantium (~> 0.2.0)
|
49
|
-
anima (~> 0.2.0)
|
50
|
-
ast (~> 2.0.0)
|
51
|
-
concord (~> 0.1.4)
|
52
|
-
equalizer (~> 0.0.9)
|
53
|
-
ice_nine (~> 0.11.0)
|
54
|
-
procto (~> 0.0.2)
|
55
|
-
mutant (0.5.11)
|
56
|
-
abstract_type (~> 0.0.7)
|
57
|
-
adamantium (~> 0.2.0)
|
58
|
-
anima (~> 0.2.0)
|
59
|
-
ast (~> 2.0)
|
60
|
-
concord (~> 0.1.5)
|
61
|
-
diff-lcs (~> 1.2)
|
62
|
-
equalizer (~> 0.0.9)
|
63
|
-
ice_nine (~> 0.11.0)
|
64
|
-
inflecto (~> 0.0.2)
|
65
|
-
memoizable (~> 0.4.2)
|
66
|
-
morpher (~> 0.2.3)
|
67
|
-
parser (~> 2.1)
|
68
|
-
procto (~> 0.0.2)
|
69
|
-
unparser (~> 0.1.12)
|
70
|
-
mutant-rspec (0.5.10)
|
71
|
-
mutant (~> 0.5.10)
|
72
|
-
rspec-core (>= 2.14.1, <= 3.0.0.beta2)
|
73
|
-
parser (2.1.9)
|
74
|
-
ast (>= 1.1, < 3.0)
|
75
|
-
slop (~> 3.4, >= 3.4.5)
|
76
|
-
procto (0.0.2)
|
77
|
-
rake (10.3.1)
|
78
|
-
rspec (2.14.0)
|
79
|
-
rspec-core (~> 2.14.0)
|
80
|
-
rspec-expectations (~> 2.14.0)
|
81
|
-
rspec-mocks (~> 2.14.0)
|
82
|
-
rspec-core (2.14.8)
|
83
|
-
rspec-expectations (2.14.5)
|
84
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
85
|
-
rspec-mocks (2.14.6)
|
86
|
-
slop (3.5.0)
|
87
|
-
thread_safe (0.3.3)
|
88
|
-
unparser (0.1.12)
|
89
|
-
abstract_type (~> 0.0.7)
|
90
|
-
adamantium (~> 0.2.0)
|
91
|
-
concord (~> 0.1.4)
|
92
|
-
equalizer (~> 0.0.9)
|
93
|
-
parser (~> 2.1)
|
94
|
-
procto (~> 0.0.2)
|
95
|
-
uri_template (0.6.0)
|
96
|
-
virtus (1.0.2)
|
97
|
-
axiom-types (~> 0.1)
|
98
|
-
coercible (~> 1.0)
|
99
|
-
descendants_tracker (~> 0.0.3)
|
100
|
-
equalizer (~> 0.0.9)
|
101
|
-
|
102
|
-
PLATFORMS
|
103
|
-
ruby
|
104
|
-
|
105
|
-
DEPENDENCIES
|
106
|
-
hamster!
|
107
|
-
mutant-rspec
|
108
|
-
rake
|
109
|
-
rspec (~> 2.14)
|
110
|
-
virtus
|
111
|
-
yaks!
|
data/lib/yaks/hal_serializer.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
# application/hal+json
|
4
|
-
#
|
5
|
-
# see examples/hal01.rb
|
6
|
-
|
7
|
-
module Yaks
|
8
|
-
class HalSerializer < Serializer
|
9
|
-
|
10
|
-
def serialize
|
11
|
-
Primitivize.(serialize_resource(resource))
|
12
|
-
end
|
13
|
-
alias to_hal serialize
|
14
|
-
|
15
|
-
protected
|
16
|
-
|
17
|
-
def serialize_resource(resource)
|
18
|
-
# The HAL spec doesn't say explicitly how to deal missing values,
|
19
|
-
# looking at client behavior (Hyperagent) it seems safer to return an empty
|
20
|
-
# resource.
|
21
|
-
#
|
22
|
-
# return nil if resource.is_a? NullResource
|
23
|
-
result = resource.attributes
|
24
|
-
result = result.put(:_links, serialize_links(resource.links)) unless resource.links.empty?
|
25
|
-
result = result.put(:_embedded, serialize_embedded(resource.subresources)) unless resource.subresources.empty?
|
26
|
-
result
|
27
|
-
end
|
28
|
-
|
29
|
-
def serialize_links(links)
|
30
|
-
links.reverse.reduce(Yaks::Hash(), &method(:serialize_link))
|
31
|
-
end
|
32
|
-
|
33
|
-
def serialize_link(memo, link)
|
34
|
-
memo.put(link.rel) {|links|
|
35
|
-
slink = {href: link.uri}.merge(link.options.reject{|k,_| k==:templated})
|
36
|
-
slink.merge!(templated: true) if link.templated?
|
37
|
-
singular?(link.rel) ? slink : Yaks::List(links).cons(slink)
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
def singular?(rel)
|
42
|
-
options.fetch(:singular_links) { [] }.include?(rel)
|
43
|
-
end
|
44
|
-
|
45
|
-
def serialize_embedded(subresources)
|
46
|
-
subresources.map do |rel, resources|
|
47
|
-
[
|
48
|
-
rel,
|
49
|
-
if resources.collection?
|
50
|
-
resources.map( &method(:serialize_resource) )
|
51
|
-
else
|
52
|
-
serialize_resource(resources)
|
53
|
-
end
|
54
|
-
]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
module Yaks
|
4
|
-
class JsonApiSerializer < Serializer
|
5
|
-
def serialize
|
6
|
-
serialized = Yaks::Hash(
|
7
|
-
pluralize(profile_name.to_s) => resource.map(&method(:serialize_resource))
|
8
|
-
)
|
9
|
-
|
10
|
-
if options[:embed] == :resources
|
11
|
-
linked = resource.reduce(Yaks::Hash()) do |memo, res|
|
12
|
-
serialize_linked_subresources(res.subresources, memo)
|
13
|
-
end
|
14
|
-
serialized = serialized.put('linked', linked)
|
15
|
-
end
|
16
|
-
|
17
|
-
Primitivize.( serialized )
|
18
|
-
end
|
19
|
-
alias to_json_api serialize
|
20
|
-
|
21
|
-
def serialize_resource(resource)
|
22
|
-
result = resource.attributes
|
23
|
-
result = result.merge(Yaks::Hash(:links => serialize_links(resource.subresources))) unless resource.subresources.empty?
|
24
|
-
result
|
25
|
-
end
|
26
|
-
|
27
|
-
def serialize_links(subresources)
|
28
|
-
Yaks::Hash(subresources.map &method(:serialize_link))
|
29
|
-
end
|
30
|
-
|
31
|
-
def serialize_link(name, resource)
|
32
|
-
if options[:embed] == :links
|
33
|
-
[ name, resource.uri ]
|
34
|
-
else
|
35
|
-
[ name, resource.collection? ? resource.map(&curry_symbol(:[], :id)) : resource[:id] ]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def serialize_linked_subresources(subresources, linked)
|
40
|
-
subresources.reduce(linked) do |memo, name, resources|
|
41
|
-
serialize_linked_resources(resources, memo)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def serialize_linked_resources(resources, linked)
|
46
|
-
resources.reduce(linked) do |memo, resource|
|
47
|
-
serialize_subresource(resource, memo)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
# {shows => [{id: 3, name: 'foo'}]}
|
52
|
-
def serialize_subresource(resource, linked)
|
53
|
-
key = pluralize(profile_registry.find_by_uri(resource.profile).to_s)
|
54
|
-
set = linked.fetch(key) { Hamster.set }
|
55
|
-
linked = linked.put(key, set << serialize_resource(resource))
|
56
|
-
serialize_linked_subresources(resource.subresources, linked)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/lib/yaks/link_lookup.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Yaks
|
2
|
-
module LinkLookup
|
3
|
-
|
4
|
-
def uri
|
5
|
-
self_link = links_by_rel(:self).first
|
6
|
-
self_link.uri if self_link
|
7
|
-
end
|
8
|
-
|
9
|
-
def profile
|
10
|
-
link = links_by_rel(:profile).first
|
11
|
-
link.uri if link
|
12
|
-
end
|
13
|
-
|
14
|
-
def profile_type
|
15
|
-
profile_registry.find_by_uri(profile)
|
16
|
-
end
|
17
|
-
|
18
|
-
def links_by_rel(rel)
|
19
|
-
links.select {|link| link.rel == rel}
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
data/lib/yaks/mapper/lookup.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Yaks
|
2
|
-
class Mapper
|
3
|
-
module Lookup
|
4
|
-
|
5
|
-
def serializer_for(object_or_key)
|
6
|
-
serializer_class_for(object_or_key).new(object_or_key, options)
|
7
|
-
end
|
8
|
-
|
9
|
-
def serializer_class_for(object_or_key)
|
10
|
-
if object_or_key.respond_to?(:to_str) || object_or_key.is_a?(Symbol)
|
11
|
-
serializer_lookup.(Object.const_get(Util.singular(Util.camelize(obj.to_s))))
|
12
|
-
else
|
13
|
-
serializer_lookup.(object_or_key)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
module Yaks
|
4
|
-
class Mapper
|
5
|
-
module MapLinks
|
6
|
-
|
7
|
-
def map_links
|
8
|
-
mapped = links.map &send_with_args(:map_to_resource_link, self)
|
9
|
-
unless links.any? {|link| link.rel? :profile }
|
10
|
-
mapped = mapped.cons(Resource::Link.new(:profile, profile_registry.find_by_type(profile_type), {}))
|
11
|
-
end
|
12
|
-
mapped
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
module Yaks
|
3
|
-
# RFC6906 The "profile" link relation http://tools.ietf.org/search/rfc6906
|
4
|
-
class ProfileRegistry
|
5
|
-
class << self
|
6
|
-
include Util
|
7
|
-
|
8
|
-
def create(&blk)
|
9
|
-
blk ||= ->{}
|
10
|
-
Class.new(self).tap(&σ(:instance_eval, &blk)).new
|
11
|
-
end
|
12
|
-
|
13
|
-
def profile(type, uri)
|
14
|
-
profiles {|reg| reg.put(type, uri)}
|
15
|
-
end
|
16
|
-
|
17
|
-
def profiles
|
18
|
-
@profiles ||= Yaks::Hash()
|
19
|
-
@profiles = yield(@profiles) if block_given?
|
20
|
-
@profiles
|
21
|
-
end
|
22
|
-
|
23
|
-
def inherited(child)
|
24
|
-
child.profiles { @profiles }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def find_by_type(type)
|
29
|
-
self.class.profiles[type]
|
30
|
-
end
|
31
|
-
|
32
|
-
def find_by_uri(by_uri)
|
33
|
-
self.class.profiles.detect {|type, uri| uri == by_uri}.first
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class NullProfileRegistry
|
38
|
-
def find_by_type(type)
|
39
|
-
type.to_s
|
40
|
-
end
|
41
|
-
|
42
|
-
def find_by_uri(uri)
|
43
|
-
uri.to_sym
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class TemplateProfileRegistry
|
48
|
-
def initialize(template)
|
49
|
-
@template = URITemplate.new(template)
|
50
|
-
end
|
51
|
-
|
52
|
-
def find_by_type(type)
|
53
|
-
@template.expand(type: type)
|
54
|
-
end
|
55
|
-
|
56
|
-
def find_by_uri(uri)
|
57
|
-
@template.extract(uri).fetch(:type) { uri }.to_sym
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/lib/yaks/rel_registry.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module Yaks
|
2
|
-
class RelRegistry
|
3
|
-
end
|
4
|
-
|
5
|
-
class TemplateRelRegistry < RelRegistry
|
6
|
-
def initialize(template)
|
7
|
-
@template = URITemplate.new(template)
|
8
|
-
end
|
9
|
-
|
10
|
-
def lookup(source, destination)
|
11
|
-
@template.expand(:src => source, :dest => destination)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class NullRelRegistry < TemplateRelRegistry
|
16
|
-
def initialize
|
17
|
-
super('rel:src={src}&dest={dest}')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/lib/yaks/shared_options.rb
DELETED
data/spec/support/shorthands.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
shared_context 'shorthands' do
|
2
|
-
let(:resource) {
|
3
|
-
->(attrs, links = nil) {
|
4
|
-
Yaks::Resource.new(Yaks::Hash(attrs), links, nil)
|
5
|
-
}
|
6
|
-
}
|
7
|
-
|
8
|
-
let(:collection_resource) {
|
9
|
-
->(*attr_hashes) {
|
10
|
-
Yaks::CollectionResource.new(
|
11
|
-
nil,
|
12
|
-
Yaks::List(attr_hashes.map(&resource.method(:call)))
|
13
|
-
)
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
let(:resource_link) {
|
18
|
-
->(rel, uri, options = {}) {
|
19
|
-
Yaks::Resource::Link.new(rel, uri, options)
|
20
|
-
}
|
21
|
-
}
|
22
|
-
end
|