representors 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +18 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +126 -0
  5. data/LICENSE.md +19 -0
  6. data/README.md +28 -0
  7. data/Rakefile +10 -0
  8. data/lib/representor_support/utilities.rb +39 -0
  9. data/lib/representors.rb +5 -0
  10. data/lib/representors/errors.rb +7 -0
  11. data/lib/representors/field.rb +108 -0
  12. data/lib/representors/options.rb +67 -0
  13. data/lib/representors/representor.rb +161 -0
  14. data/lib/representors/representor_builder.rb +64 -0
  15. data/lib/representors/representor_hash.rb +59 -0
  16. data/lib/representors/serialization.rb +4 -0
  17. data/lib/representors/serialization/deserializer_base.rb +29 -0
  18. data/lib/representors/serialization/deserializer_factory.rb +13 -0
  19. data/lib/representors/serialization/hal_deserializer.rb +44 -0
  20. data/lib/representors/serialization/hal_serializer.rb +91 -0
  21. data/lib/representors/serialization/hale_deserializer.rb +162 -0
  22. data/lib/representors/serialization/hale_serializer.rb +110 -0
  23. data/lib/representors/serialization/serialization_base.rb +27 -0
  24. data/lib/representors/serialization/serialization_factory_base.rb +54 -0
  25. data/lib/representors/serialization/serializer_base.rb +20 -0
  26. data/lib/representors/serialization/serializer_factory.rb +17 -0
  27. data/lib/representors/transition.rb +130 -0
  28. data/lib/representors/version.rb +4 -0
  29. data/spec/fixtures/complex_hal.json +92 -0
  30. data/spec/fixtures/complex_hale_document.json +81 -0
  31. data/spec/fixtures/drds_hash.rb +120 -0
  32. data/spec/fixtures/hale_spec_examples/basic.json +77 -0
  33. data/spec/fixtures/hale_spec_examples/complex_reference_objects.json +157 -0
  34. data/spec/fixtures/hale_spec_examples/data.json +17 -0
  35. data/spec/fixtures/hale_spec_examples/data_objects.json +96 -0
  36. data/spec/fixtures/hale_spec_examples/link_objects.json +18 -0
  37. data/spec/fixtures/hale_spec_examples/nested_ref.json +43 -0
  38. data/spec/fixtures/hale_spec_examples/reference_objects.json +89 -0
  39. data/spec/fixtures/hale_tutorial_examples/basic_links.json +85 -0
  40. data/spec/fixtures/hale_tutorial_examples/basic_links_with_orders.json +96 -0
  41. data/spec/fixtures/hale_tutorial_examples/basic_links_with_references.json +108 -0
  42. data/spec/fixtures/hale_tutorial_examples/embedded.json +182 -0
  43. data/spec/fixtures/hale_tutorial_examples/empty.json +1 -0
  44. data/spec/fixtures/hale_tutorial_examples/enctype.json +14 -0
  45. data/spec/fixtures/hale_tutorial_examples/final.json +141 -0
  46. data/spec/fixtures/hale_tutorial_examples/get_link.json +17 -0
  47. data/spec/fixtures/hale_tutorial_examples/get_link_with_data.json +29 -0
  48. data/spec/fixtures/hale_tutorial_examples/links.json +11 -0
  49. data/spec/fixtures/hale_tutorial_examples/links_only.json +3 -0
  50. data/spec/fixtures/hale_tutorial_examples/meta.json +208 -0
  51. data/spec/fixtures/hale_tutorial_examples/self_link.json +7 -0
  52. data/spec/fixtures/single_drd.rb +266 -0
  53. data/spec/lib/representors/complex_representor_spec.rb +288 -0
  54. data/spec/lib/representors/field_spec.rb +141 -0
  55. data/spec/lib/representors/representor_builder_spec.rb +223 -0
  56. data/spec/lib/representors/representor_spec.rb +285 -0
  57. data/spec/lib/representors/serialization/deserializer_factory_spec.rb +118 -0
  58. data/spec/lib/representors/serialization/hal_deserializer_spec.rb +34 -0
  59. data/spec/lib/representors/serialization/hal_serializer_spec.rb +171 -0
  60. data/spec/lib/representors/serialization/hale_deserializer_spec.rb +59 -0
  61. data/spec/lib/representors/serialization/hale_roundtrip_spec.rb +34 -0
  62. data/spec/lib/representors/serialization/hale_serializer_spec.rb +659 -0
  63. data/spec/lib/representors/serialization/serializer_factory_spec.rb +108 -0
  64. data/spec/lib/representors/transition_spec.rb +349 -0
  65. data/spec/spec_helper.rb +32 -0
  66. data/spec/support/basic-hale.json +12 -0
  67. data/spec/support/hal_representor_shared.rb +206 -0
  68. data/spec/support/helpers.rb +8 -0
  69. data/tasks/benchmark.rake +75 -0
  70. data/tasks/complex_hal_document.json +98 -0
  71. data/tasks/test_specs.rake +37 -0
  72. data/tasks/yard.rake +22 -0
  73. metadata +232 -0
@@ -0,0 +1,17 @@
1
+ {
2
+ "_links": {
3
+ "self": {
4
+ "href": "www.example.com/coffeebucks/"
5
+ },
6
+ "profile": {
7
+ "href": "profiles.example.com/coffeebucks/",
8
+ "enctype": [
9
+ "application/alps+xml",
10
+ "text/html"
11
+ ]
12
+ },
13
+ "orders": {
14
+ "href": "www.example.com/coffeebucks"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "_links": {
3
+ "self": {
4
+ "href": "www.example.com/coffeebucks/"
5
+ },
6
+ "profile": {
7
+ "href": "profiles.example.com/coffeebucks/",
8
+ "enctype": [
9
+ "application/alps+xml",
10
+ "text/html"
11
+ ]
12
+ },
13
+ "orders": {
14
+ "href": "www.example.com/coffeebucks{?order_status}",
15
+ "data": {
16
+ "order_status": {
17
+ "scope": "href",
18
+ "options": [
19
+ "pending_payment",
20
+ "preparing",
21
+ "fulfilled"
22
+ ],
23
+ "in": true,
24
+ "multi": true
25
+ }
26
+ }
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "_links": {
3
+ "self": {
4
+ "href": "www.example.com/coffeebucks/"
5
+ },
6
+ "profile": {
7
+ "href": "profiles.example.com/coffeebucks/",
8
+ "enctype": "application/alps+xml"
9
+ }
10
+ }
11
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "_links": {}
3
+ }
@@ -0,0 +1,208 @@
1
+ {
2
+ "_meta": {
3
+ "order_properties": {
4
+ "drink_type": {
5
+ "options": [
6
+ "coffee",
7
+ "americano",
8
+ "latte",
9
+ "mocha",
10
+ "cappuccino",
11
+ "macchiato",
12
+ "espresso"
13
+ ],
14
+ "in": true,
15
+ "required": true
16
+ },
17
+ "iced": {
18
+ "type": "boolean",
19
+ "value": false
20
+ },
21
+ "size": {
22
+ "type": "integer:number",
23
+ "options": [
24
+ {
25
+ "small": 8
26
+ },
27
+ {
28
+ "medium": 12
29
+ },
30
+ {
31
+ "large": 16
32
+ },
33
+ {
34
+ "extra-large": 20
35
+ }
36
+ ],
37
+ "in": true,
38
+ "required": true
39
+ },
40
+ "shots": {
41
+ "type": "integer:range",
42
+ "min": 0,
43
+ "max": 16
44
+ },
45
+ "decaf": {
46
+ "type": "integer:range",
47
+ "min": 0,
48
+ "max": 16,
49
+ "lte": {
50
+ "profile": "profiles.example.com/lte/",
51
+ "attribute": "shots"
52
+ }
53
+ }
54
+ }
55
+ },
56
+ "_links": {
57
+ "self": {
58
+ "href": "www.example.com/coffeebucks/"
59
+ },
60
+ "profile": {
61
+ "href": "profiles.example.com/coffeebucks/",
62
+ "enctype": [
63
+ "application/alps+xml",
64
+ "text/html"
65
+ ]
66
+ },
67
+ "orders": {
68
+ "href": "www.example.com/coffeebucks{?order_status,page}",
69
+ "data": {
70
+ "order_status": {
71
+ "scope": "href",
72
+ "options": [
73
+ "pending_payment",
74
+ "preparing",
75
+ "fulfilled"
76
+ ],
77
+ "in": true,
78
+ "multi": true
79
+ },
80
+ "page": {
81
+ "type": "integer",
82
+ "min": 1,
83
+ "max": 2,
84
+ "value": 1
85
+ }
86
+ }
87
+ },
88
+ "next": {
89
+ "href": "www.example.com/coffeebucks?page=2"
90
+ },
91
+ "place_order": {
92
+ "href": "www.example.com/coffeebucks/orders",
93
+ "method": "POST",
94
+ "data": {
95
+ "_ref": [
96
+ "order_properties"
97
+ ]
98
+ },
99
+ "multi_order": {
100
+ "href": "www.example.com/coffeebucks/orders",
101
+ "request_encoding": "application/json",
102
+ "method": "POST",
103
+ "data": {
104
+ "multi_order": {
105
+ "value": true
106
+ },
107
+ "orders": {
108
+ "type": "object",
109
+ "multi": "true",
110
+ "data": {
111
+ "_ref": [
112
+ "order_properties"
113
+ ]
114
+ }
115
+ }
116
+ }
117
+ }
118
+ },
119
+ "order_list": [
120
+ {
121
+ "href": "www.example.com/coffeebucks/1"
122
+ },
123
+ {
124
+ "href": "www.example.com/coffeebucks/2"
125
+ },
126
+ {
127
+ "href": "www.example.com/coffeebucks/3"
128
+ }
129
+ ]
130
+ },
131
+ "_embedded": {
132
+ "order_list": [
133
+ {
134
+ "_links": {
135
+ "self": {
136
+ "href": "www.example.com/coffeebucks/1"
137
+ },
138
+ "fulfill": {
139
+ "href": "www.example.com/coffeebucks/1",
140
+ "method": "PUT",
141
+ "data": {
142
+ "status": {
143
+ "value": "fulfilled",
144
+ "required": true
145
+ }
146
+ }
147
+ }
148
+ },
149
+ "status": "preparing",
150
+ "created": 12569537329,
151
+ "drink_type": "latte",
152
+ "iced": "true",
153
+ "size": 8,
154
+ "shots": 2,
155
+ "decaf": 1
156
+ },
157
+ {
158
+ "_links": {
159
+ "self": {
160
+ "href": "www.example.com/coffeebucks/2"
161
+ }
162
+ },
163
+ "status": "fulfilled",
164
+ "created": 12569537312,
165
+ "drink_type": "latte",
166
+ "iced": "true",
167
+ "size": 8,
168
+ "shots": 2,
169
+ "decaf": 1
170
+ },
171
+ {
172
+ "_links": {
173
+ "self": {
174
+ "href": "www.example.com/coffeebucks/3"
175
+ },
176
+ "prepare": {
177
+ "href": "www.example.com/coffeebucks/1",
178
+ "method": "PUT",
179
+ "data": {
180
+ "status": {
181
+ "value": "preparing",
182
+ "required": true
183
+ },
184
+ "paid": {
185
+ "value": 495,
186
+ "required": true
187
+ }
188
+ }
189
+ },
190
+ "cancel": {
191
+ "href": "www.example.com/coffeebucks/3",
192
+ "method": "DELETE"
193
+ }
194
+ },
195
+ "status": "pending_payment",
196
+ "created": 12569534536,
197
+ "drink_type": "latte",
198
+ "iced": "true",
199
+ "size": 8,
200
+ "shots": 2,
201
+ "decaf": 1,
202
+ "cost": 495
203
+ }
204
+ ]
205
+ },
206
+ "count": 3,
207
+ "total_count": 6
208
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "_links": {
3
+ "self": {
4
+ "href": "www.example.com/coffeebucks/"
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,266 @@
1
+ module ComplexRepresentor
2
+ DRD_HASH = {
3
+ href: 'http://example.com/drd/1',
4
+ id: 'DRD',
5
+ doc: 'Diagnostic Repair Drones or DRDs are small robots that move around Leviathans. They are built by a Leviathan as it grows.',
6
+ links: {
7
+ profile: 'http://www.example.com/drds/show/DRD',
8
+ help: 'http://alps.io/schema.org/DRD'
9
+ },
10
+ attributes: {
11
+ uuid: {
12
+ doc: 'The UUID of the DRD.',
13
+ profile: 'http://alps.io/schema.org/Text',
14
+ sample: '007d8e12-babd-4f2c-b01e-8b5e2f749e1z',
15
+ value: '007d8e12-babd-4f2c-b01e-8b5e2f749e1z',
16
+ },
17
+ name: {
18
+ doc: 'The name of the DRD.',
19
+ profile: 'http://alps.io/schema.org/Text',
20
+ sample: 'drdname',
21
+ value: 'drdname',
22
+ },
23
+ status: {
24
+ doc: 'How is the DRD.',
25
+ profile: 'http://alps.io/schema.org/Text',
26
+ sample: 'renegade',
27
+ value: 'compliant',
28
+ },
29
+ old_status: {
30
+ doc: 'How was the DRD before the last change',
31
+ profile: 'http://alps.io/schema.org/Text',
32
+ sample: 'renegade',
33
+ value: 'compliant',
34
+ },
35
+ kind: {
36
+ doc: 'What kind is it.',
37
+ profile: 'http://alps.io/schema.org/Text',
38
+ sample: 'standard',
39
+ value: 'nonstandard',
40
+ },
41
+ size: {
42
+ doc: 'How large it is',
43
+ profile: 'http://alps.io/schema.org/Text',
44
+ sample: 'medium',
45
+ value: 'medium',
46
+ },
47
+ leviathan_uuid: {
48
+ doc: 'The UUID of the creator Leviathan.',
49
+ profile: 'http://alps.io/schema.org/Text',
50
+ sample: '007d8e12-babd-4f2c-b01e-8b5e2f749e1b',
51
+ value: '007d8e12-babd-b01e-4f2c-8b5e2f749e1b',
52
+ },
53
+ built_at: {
54
+ doc: 'When the DRD was constructed.',
55
+ profile: 'http://alps.io/schema.org/DateTime',
56
+ sample: '2013-03-20T00:00:00+00:00',
57
+ value: '2013-03-20T00:00:00+00:01',
58
+ },
59
+ leviathan: {
60
+ doc: 'The associated Leviathan resource.',
61
+ profile: 'http://alps.io/schema.org/Thing/Leviathan',
62
+ sample: 'http://alps.io/schema.org/Thing/Leviathan',
63
+ value: 'http://alps.io/schema.org/Thing/Leviathan',
64
+ },
65
+ location: {
66
+ doc: 'The area the DRD is currently in',
67
+ profile: 'http://alps.io/schema.org/Text',
68
+ sample: 'moya',
69
+ multiple: 'true',
70
+ value: ['moya','japan'],
71
+ },
72
+ location_detail: {
73
+ doc: 'Exactly where in the location the DRD currenlty is',
74
+ profile: 'http://alps.io/schema.org/Text',
75
+ sample: 'outside',
76
+ value: 'inside',
77
+ },
78
+ leviathan_email: {
79
+ doc: 'The Leviathan respond to email.',
80
+ profile: 'http://alps.io/schema.org/Text',
81
+ sample: 'joe@grumpycat.org',
82
+ value: 'joe@grumpycat.org',
83
+ },
84
+ leviathan_uuid: {
85
+ doc: 'The UUID of the creator Leviathan.',
86
+ profile: 'http://alps.io/schema.org/Text',
87
+ sample: '1234-5678-9abc-def1',
88
+ value: '1234-9abc-5678-def1',
89
+ },
90
+ destroyed: {
91
+ doc: 'This DRD has been destroyed',
92
+ profile: 'http://alps.io/schema.org/Boolean',
93
+ sample: 'destroyed',
94
+ value: 'destroyed',
95
+ },
96
+ leviathan_health_points: {
97
+ doc: 'The health points of Leviathan.',
98
+ profile: 'http://alps.io/schema.org/Integer',
99
+ value: 32,
100
+ },
101
+ term: {
102
+ doc: 'The terms to search.',
103
+ profile: 'http://alps.io/schema.org/Text',
104
+ sample: 'searchterm',
105
+ value: 'blunderbus',
106
+ },
107
+ },
108
+ transitions: [
109
+ {
110
+ rel: 'self',
111
+ doc: 'Shows a particular DRD.',
112
+ profile: 'http://alps.io/schema.org/DRD',
113
+ href: 'www.example.com/drds/show/173875983789',
114
+ },
115
+ {
116
+ rel: 'show',
117
+ doc: 'Shows a particular DRD.',
118
+ profile: 'http://alps.io/schema.org/DRD',
119
+ href: 'www.example.com/drds/show/173875983789',
120
+ },
121
+ {
122
+ rel: 'leviathan-link',
123
+ name: 'leviathan',
124
+ doc: 'A reference to the Leviathan the DRD works on.',
125
+ embed: true,
126
+ profile: 'http://alps.io/schema.org/Leviathan#leviathan',
127
+ href: 'http://example.com/drds/Leviathan',
128
+ },
129
+ {
130
+ rel: 'repair-history',
131
+ doc: 'A reference to the list of historical repairs performed.',
132
+ embed: true,
133
+ profile: 'http://alps.io/schema.org/Repairs#history',
134
+ href: 'http://example.com/drds/Repairs',
135
+ },
136
+ {
137
+ rel: 'activate',
138
+ doc: 'Activates a DRD if it is deactivated.',
139
+ profile: 'http://alps.io/schema.org/DRD',
140
+ href: 'http://example.com/drds/activate/173875983789',
141
+ method: 'PUT',
142
+ },
143
+ {
144
+ rel: 'deactivate',
145
+ doc: 'Deactivates a DRD if it is activated.',
146
+ profile: 'http://alps.io/schema.org/DRD',
147
+ href: 'http://example.com/drds/show/173875983789',
148
+ method: 'PUT',
149
+ },
150
+ {
151
+ rel: 'delete',
152
+ doc: 'Drops a DRD out an air-lock.',
153
+ href: 'http://example.com/drds/show/173875983789',
154
+ method: 'DELETE',
155
+ },
156
+ {
157
+ rel: 'update',
158
+ doc: 'Updates a DRD.',
159
+ profile: 'http://alps.io/schema.org/DRDs#update',
160
+ href: 'http://example.com/drds/show/173875983789',
161
+ method: 'PUT',
162
+ descriptors: {
163
+ links: {
164
+ self: 'http://alps.io/schema.org/DRDs#update',
165
+ help: 'http://help.example.com/Forms/update',
166
+ },
167
+ status: {
168
+ doc: 'How is the DRD.',
169
+ profile: 'http://alps.io/schema.org/Text',
170
+ sample: 'renegade',
171
+ value: 'renegade',
172
+ type: 'text',
173
+ data_type: 'select',
174
+ validators: [
175
+ :required,
176
+ ],
177
+ options: {
178
+ 'id' => 'drd_status_options',
179
+ 'hash' => {
180
+ 'active' => 'activated',
181
+ 'inactive' => 'deactivated',
182
+ 'unknown' => 'renegade',
183
+ },
184
+ },
185
+ },
186
+ old_status: {
187
+ doc: 'How was the DRD before the last change',
188
+ profile: 'http://alps.io/schema.org/Text',
189
+ sample: 'renegade',
190
+ type: 'text',
191
+ data_type: 'select',
192
+ validators: [
193
+ :required,
194
+ ],
195
+ options: {
196
+ 'id' => 'drd_status_options',
197
+ 'hash' => {
198
+ 'active' => 'activated',
199
+ 'inactive' => 'deactivated',
200
+ 'unknow' => 'renegade',
201
+ },
202
+ },
203
+ },
204
+ kind: {
205
+ doc: 'What kind is it.',
206
+ profile: 'http://alps.io/schema.org/Text',
207
+ sample: 'standard',
208
+ type: 'text',
209
+ data_type: 'select',
210
+ options: {
211
+ 'list' => [
212
+ 'standard',
213
+ 'sentinel',
214
+ ]
215
+ },
216
+ },
217
+ size: {
218
+ doc: 'How large it is',
219
+ profile: 'http://alps.io/schema.org/Text',
220
+ sample: 'medium',
221
+ type: 'text',
222
+ data_type: 'text',
223
+ options: {
224
+ 'list' => [
225
+ 'big',
226
+ 'small',
227
+ ],
228
+ },
229
+ },
230
+ location: {
231
+ doc: 'The area the DRD is currently in',
232
+ profile: 'http://alps.io/schema.org/Text',
233
+ sample: 'moya',
234
+ multiple: 'true',
235
+ field_type: 'select',
236
+ options: {
237
+ 'external' => {
238
+ 'source' => 'http://crichton.example.com/drd_location_detail_list#items',
239
+ },
240
+ },
241
+ },
242
+ location_detail: {
243
+ doc: 'Exactly where in the location the DRD currenlty is',
244
+ profile: 'http://alps.io/schema.org/Text',
245
+ sample: 'outside',
246
+ field_type: 'select',
247
+ options: {
248
+ 'external' => {
249
+ 'source' => 'http://crichton.example.com/drd_location_detail_list#items',
250
+ 'target' => 'location_detail_id',
251
+ 'prompt' => 'location_detail_text',
252
+ },
253
+ },
254
+ },
255
+ destroyed: {
256
+ doc: 'This DRD has been destroyed',
257
+ profile: 'http://alps.io/schema.org/Boolean',
258
+ sample: true,
259
+ type: 'boolean',
260
+ field_type: 'boolean',
261
+ },
262
+ },
263
+ },
264
+ ],
265
+ }
266
+ end