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,108 @@
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,page}",
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
+ "page": {
27
+ "scope": "href",
28
+ "type": "integer",
29
+ "min": 1,
30
+ "max": 2,
31
+ "value": 1
32
+ }
33
+ }
34
+ },
35
+ "next": {
36
+ "href": "www.example.com/coffeebucks?page=2"
37
+ },
38
+ "place_order": {
39
+ "href": "www.example.com/coffeebucks/orders",
40
+ "method": "POST",
41
+ "data": {
42
+ "drink_type": {
43
+ "options": [
44
+ "coffee",
45
+ "americano",
46
+ "latte",
47
+ "mocha",
48
+ "cappuccino",
49
+ "macchiato",
50
+ "espresso"
51
+ ],
52
+ "in": true,
53
+ "required": true
54
+ },
55
+ "iced": {
56
+ "type": "boolean",
57
+ "value": false
58
+ },
59
+ "size": {
60
+ "type": "integer: number",
61
+ "options": [
62
+ {
63
+ "small": 8
64
+ },
65
+ {
66
+ "medium": 12
67
+ },
68
+ {
69
+ "large": 16
70
+ },
71
+ {
72
+ "extra-large": 20
73
+ }
74
+ ],
75
+ "in": true,
76
+ "required": true
77
+ },
78
+ "shots": {
79
+ "type": "integer: range",
80
+ "min": 0,
81
+ "max": 16
82
+ },
83
+ "decaf": {
84
+ "type": "integer: range",
85
+ "min": 0,
86
+ "max": 16,
87
+ "lte": {
88
+ "profile": "profiles.example.com/lte/",
89
+ "attribute": "shots"
90
+ }
91
+ }
92
+ }
93
+ },
94
+ "order_list": [
95
+ {
96
+ "href": "www.example.com/coffeebucks/1"
97
+ },
98
+ {
99
+ "href": "www.example.com/coffeebucks/2"
100
+ },
101
+ {
102
+ "href": "www.example.com/coffeebucks/3"
103
+ }
104
+ ]
105
+ },
106
+ "count": 3,
107
+ "total_count": 6
108
+ }
@@ -0,0 +1,182 @@
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,page}",
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
+ "page": {
27
+ "type": "integer",
28
+ "min": 1,
29
+ "max": 2,
30
+ "value": 1
31
+ }
32
+ }
33
+ },
34
+ "next": {
35
+ "href": "www.example.com/coffeebucks?page=2"
36
+ },
37
+ "place_order": {
38
+ "href": "www.example.com/coffeebucks/orders",
39
+ "method": "POST",
40
+ "data": {
41
+ "drink_type": {
42
+ "options": [
43
+ "coffee",
44
+ "americano",
45
+ "latte",
46
+ "mocha",
47
+ "cappuccino",
48
+ "macchiato",
49
+ "espresso"
50
+ ],
51
+ "in": true,
52
+ "required": true
53
+ },
54
+ "iced": {
55
+ "type": "boolean",
56
+ "value": false
57
+ },
58
+ "size": {
59
+ "type": "integer:number",
60
+ "options": [
61
+ {
62
+ "small": 8
63
+ },
64
+ {
65
+ "medium": 12
66
+ },
67
+ {
68
+ "large": 16
69
+ },
70
+ {
71
+ "extra-large": 20
72
+ }
73
+ ],
74
+ "in": true,
75
+ "required": true
76
+ },
77
+ "shots": {
78
+ "type": "integer:range",
79
+ "min": 0,
80
+ "max": 16
81
+ },
82
+ "decaf": {
83
+ "type": "integer:range",
84
+ "min": 0,
85
+ "max": 16,
86
+ "lte": {
87
+ "profile": "profiles.example.com/lte/",
88
+ "attribute": "shots"
89
+ }
90
+ }
91
+ }
92
+ },
93
+ "order_list": [
94
+ {
95
+ "href": "www.example.com/coffeebucks/1"
96
+ },
97
+ {
98
+ "href": "www.example.com/coffeebucks/2"
99
+ },
100
+ {
101
+ "href": "www.example.com/coffeebucks/3"
102
+ }
103
+ ]
104
+ },
105
+ "_embedded": {
106
+ "order_list": [
107
+ {
108
+ "_links": {
109
+ "self": {
110
+ "href": "www.example.com/coffeebucks/1"
111
+ },
112
+ "fulfill": {
113
+ "href": "www.example.com/coffeebucks/1",
114
+ "method": "PUT",
115
+ "data": {
116
+ "status": {
117
+ "value": "fulfilled",
118
+ "required": true
119
+ }
120
+ }
121
+ }
122
+ },
123
+ "status": "preparing",
124
+ "created": 12569537329,
125
+ "drink_type": "latte",
126
+ "iced": "true",
127
+ "size": 8,
128
+ "shots": 2,
129
+ "decaf": 1
130
+ },
131
+ {
132
+ "_links": {
133
+ "self": {
134
+ "href": "www.example.com/coffeebucks/2"
135
+ }
136
+ },
137
+ "status": "fulfilled",
138
+ "created": 12569537312,
139
+ "drink_type": "latte",
140
+ "iced": "true",
141
+ "size": 8,
142
+ "shots": 2,
143
+ "decaf": 1
144
+ },
145
+ {
146
+ "_links": {
147
+ "self": {
148
+ "href": "www.example.com/coffeebucks/3"
149
+ },
150
+ "prepare": {
151
+ "href": "www.example.com/coffeebucks/1",
152
+ "method": "PUT",
153
+ "data": {
154
+ "status": {
155
+ "value": "preparing",
156
+ "required": true
157
+ },
158
+ "paid": {
159
+ "value": 495,
160
+ "required": true
161
+ }
162
+ }
163
+ },
164
+ "cancel": {
165
+ "href": "www.example.com/coffeebucks/3",
166
+ "method": "DELETE"
167
+ }
168
+ },
169
+ "status": "pending_payment",
170
+ "created": 12569534536,
171
+ "drink_type": "latte",
172
+ "iced": "true",
173
+ "size": 8,
174
+ "shots": 2,
175
+ "decaf": 1,
176
+ "cost": 495
177
+ }
178
+ ]
179
+ },
180
+ "count": 3,
181
+ "total_count": 6
182
+ }
@@ -0,0 +1,14 @@
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
+ }
14
+ }
@@ -0,0 +1,141 @@
1
+ {
2
+ "_meta": {
3
+ "shot_base": {
4
+ "type": "integer:range",
5
+ "min": 0,
6
+ "max": 16
7
+ },
8
+ "order_properties": {
9
+ "drink_type": {
10
+ "options": {
11
+ "_ref": [
12
+ {
13
+ "href": "www.example.com/hq/menu",
14
+ "type": "application/xml",
15
+ "target": "/menu/menuitem[current=true]/item_name[text()]"
16
+ }
17
+ ]
18
+ },
19
+ "in": true,
20
+ "required": true
21
+ },
22
+ "iced": {
23
+ "type": "boolean",
24
+ "value": false
25
+ },
26
+ "size": {
27
+ "type": "integer:number",
28
+ "options": [
29
+ {
30
+ "small": 8
31
+ },
32
+ {
33
+ "medium": 12
34
+ },
35
+ {
36
+ "large": 16
37
+ },
38
+ {
39
+ "extra-large": 20
40
+ }
41
+ ],
42
+ "in": true,
43
+ "required": true
44
+ },
45
+ "shots": {
46
+ "_ref": [
47
+ "shot_base"
48
+ ]
49
+ },
50
+ "decaf": {
51
+ "_ref": [
52
+ "shot_base"
53
+ ],
54
+ "lte": {
55
+ "profile": "profiles.example.com/lte/",
56
+ "attribute": "shots"
57
+ }
58
+ }
59
+ }
60
+ },
61
+ "_links": {
62
+ "self": {
63
+ "href": "www.example.com/coffeebucks/"
64
+ },
65
+ "profile": {
66
+ "href": "profiles.example.com/coffeebucks/",
67
+ "enctype": [
68
+ "application/alps+xml",
69
+ "text/html"
70
+ ]
71
+ },
72
+ "orders": {
73
+ "href": "www.example.com/coffeebucks{?order_status,page}",
74
+ "data": {
75
+ "order_status": {
76
+ "scope": "href",
77
+ "options": [
78
+ "pending_payment",
79
+ "preparing",
80
+ "fulfilled"
81
+ ],
82
+ "in": true,
83
+ "multi": true
84
+ },
85
+ "page": {
86
+ "type": "integer",
87
+ "min": 1,
88
+ "max": 2,
89
+ "value": 1
90
+ }
91
+ }
92
+ },
93
+ "next": {
94
+ "href": "www.example.com/coffeebucks?page=2"
95
+ },
96
+ "place_order": {
97
+ "href": "www.example.com/coffeebucks/orders",
98
+ "method": "POST",
99
+ "data": {
100
+ "_ref": [
101
+ "order_properties"
102
+ ]
103
+ },
104
+ "multi_order": {
105
+ "href": "www.example.com/coffeebucks/orders",
106
+ "request_encoding": "application/json",
107
+ "method": "POST",
108
+ "data": {
109
+ "multi_order": {
110
+ "value": true
111
+ },
112
+ "orders": {
113
+ "type": "object",
114
+ "multi": "true",
115
+ "data": {
116
+ "_ref": [
117
+ "order_properties"
118
+ ]
119
+ }
120
+ }
121
+ }
122
+ }
123
+ },
124
+ "order_list": [
125
+ {
126
+ "href": "www.example.com/coffeebucks/1",
127
+ "render": "embed"
128
+ },
129
+ {
130
+ "href": "www.example.com/coffeebucks/2",
131
+ "render": "embed"
132
+ },
133
+ {
134
+ "href": "www.example.com/coffeebucks/3",
135
+ "render": "embed"
136
+ }
137
+ ]
138
+ },
139
+ "count": 3,
140
+ "total_count": 6
141
+ }