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
+ "search": {
4
+ "href": ".../{?state}",
5
+ "data": {
6
+ "state": {
7
+ "options": [
8
+ "AL",
9
+ "...",
10
+ "WY"
11
+ ],
12
+ "in": true
13
+ }
14
+ }
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,96 @@
1
+ {
2
+ "_links": {
3
+ "self": {
4
+ "href": "...",
5
+ "method": "GET"
6
+ },
7
+ "search": {
8
+ "href": ".../{?search_term,state}",
9
+ "method": "GET",
10
+ "data": {
11
+ "state": {
12
+ "options": [
13
+ "AL",
14
+ "...",
15
+ "WY"
16
+ ],
17
+ "multi": true
18
+ }
19
+ }
20
+ },
21
+ "create": {
22
+ "href": ".../{?user}",
23
+ "method": "POST",
24
+ "request_encoding": "application/x-www-form-urlencoded",
25
+ "data": {
26
+ "user": {
27
+ "scope": "href",
28
+ "required": true
29
+ },
30
+ "given_name": {
31
+ "minlength": 4,
32
+ "maxlength": 30,
33
+ "required": true,
34
+ "profile": "http://alps.io/schema.org/Person#givenName"
35
+ },
36
+ "family_name": {
37
+ "type": "string",
38
+ "profile": "http://alps.io/schema.org/Person#familyName"
39
+ },
40
+ "parents": {
41
+ "type": "array",
42
+ "profile": "http://alps.io/schema.org/Person",
43
+ "data": {
44
+ "given_name": {
45
+ "minlength": 4,
46
+ "maxlength": 30,
47
+ "required": true,
48
+ "profile": "http://alps.io/schema.org/Person#givenName"
49
+ },
50
+ "family_name": {
51
+ "type": "string",
52
+ "profile": "http://alps.io/schema.org/Person#familyName"
53
+ }
54
+ }
55
+ },
56
+ "email_address": {
57
+ "type": "string:email",
58
+ "required": true
59
+ },
60
+ "phone": {
61
+ "type": "number:tel"
62
+ },
63
+ "phone_ext": {
64
+ "min": 0,
65
+ "max": 6
66
+ },
67
+ "ssn": {
68
+ "pattern": "^(\\d{3}-?\\d{2}-?\\d{4}|XXX-XX-XXXX)$"
69
+ },
70
+ "home": {
71
+ "type": "object",
72
+ "required": false,
73
+ "data": {
74
+ "address": {
75
+ "type": "string"
76
+ },
77
+ "city": {
78
+ "type": "string"
79
+ },
80
+ "state": {
81
+ "options": [
82
+ "AL",
83
+ "...",
84
+ "WY"
85
+ ],
86
+ "in": true
87
+ },
88
+ "postal_code": {
89
+ "type": "number"
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
96
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "_meta": {
3
+ "monster": {
4
+ "demeanor": "scary"
5
+ },
6
+ "explosion": {
7
+ "occupation": "swamp thing",
8
+ "_ref": [
9
+ {
10
+ "href": "/human/1",
11
+ "method": "GET",
12
+ "type": "application/json"
13
+ },
14
+ "monster"
15
+ ]
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "_meta": {
3
+ "data": {
4
+ "options": [
5
+ 0,
6
+ 1,
7
+ 2
8
+ ],
9
+ "value": 0
10
+ },
11
+ "data1": {
12
+ "_ref": [
13
+ "data"
14
+ ],
15
+ "value": 1
16
+ },
17
+ "something": {
18
+ "max": 1,
19
+ "value": 2
20
+ },
21
+ "something_else": {
22
+ "_ref": [
23
+ "data1",
24
+ "something"
25
+ ]
26
+ }
27
+ },
28
+ "_embedded": {
29
+ "item": {
30
+ "_meta": {
31
+ "embedded_something": {
32
+ "_ref": [
33
+ "something_else"
34
+ ]
35
+ }
36
+ },
37
+ "_links": {
38
+ "self": { "href": "/thing/1", "method": "GET" }
39
+ }
40
+
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,89 @@
1
+ {
2
+ "_meta": {
3
+ "lookup": {
4
+ "send_info": {
5
+ "options": [
6
+ "yes",
7
+ "no",
8
+ "maybe"
9
+ ],
10
+ "in": true
11
+ }
12
+ },
13
+ "edit_form": {
14
+ "_ref": [
15
+ {
16
+ "href": "/edit_form/1",
17
+ "method": "GET",
18
+ "type": "application/json"
19
+ }
20
+ ]
21
+ }
22
+ },
23
+ "_links": {
24
+ "self": {
25
+ "href": "..."
26
+ },
27
+ "search": {
28
+ "href": ".../{?send_info}",
29
+ "templated": true,
30
+ "method": "GET",
31
+ "data": {
32
+ "_ref": [
33
+ "lookup"
34
+ ]
35
+ }
36
+ },
37
+ "agent": {
38
+ "href": "/agent/1",
39
+ "method": "GET",
40
+ "render": "embed"
41
+ },
42
+ "customer": [
43
+ {
44
+ "href": "/customer/1",
45
+ "method": "GET"
46
+ },
47
+ {
48
+ "href": "/customer/2",
49
+ "method": "GET"
50
+ }
51
+ ]
52
+ },
53
+ "_embedded": {
54
+ "customer": [
55
+ {
56
+ "_links": {
57
+ "self": {
58
+ "href": "/customer/1",
59
+ "method": "GET"
60
+ },
61
+ "edit": {
62
+ "href": ".../{?user_id}",
63
+ "_ref": [
64
+ "edit_form"
65
+ ]
66
+ }
67
+ },
68
+ "name": "Tom",
69
+ "send_info": "yes"
70
+ },
71
+ {
72
+ "_links": {
73
+ "self": {
74
+ "href": "/customer/2",
75
+ "method": "GET"
76
+ },
77
+ "edit": {
78
+ "href": ".../{?user_id}",
79
+ "_ref": [
80
+ "edit_form"
81
+ ]
82
+ }
83
+ },
84
+ "name": "Harry",
85
+ "send_info": "no"
86
+ }
87
+ ]
88
+ }
89
+ }
@@ -0,0 +1,85 @@
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
+ "place_order": {
29
+ "href": "www.example.com/coffeebucks/orders",
30
+ "method": "POST",
31
+ "data": {
32
+ "drink_type": {
33
+ "options": [
34
+ "coffee",
35
+ "americano",
36
+ "latte",
37
+ "mocha",
38
+ "cappuccino",
39
+ "macchiato",
40
+ "espresso"
41
+ ],
42
+ "in": true,
43
+ "required": true
44
+ },
45
+ "iced": {
46
+ "type": "boolean",
47
+ "value": false
48
+ },
49
+ "size": {
50
+ "type": "integer:number",
51
+ "options": [
52
+ {
53
+ "small": 8
54
+ },
55
+ {
56
+ "medium": 12
57
+ },
58
+ {
59
+ "large": 16
60
+ },
61
+ {
62
+ "extra-large": 20
63
+ }
64
+ ],
65
+ "in": true,
66
+ "required": true
67
+ },
68
+ "shots": {
69
+ "type": "integer:range",
70
+ "min": 0,
71
+ "max": 16
72
+ },
73
+ "decaf": {
74
+ "type": "integer:range",
75
+ "min": 0,
76
+ "max": 16,
77
+ "lte": {
78
+ "profile": "profiles.example.com/lte/",
79
+ "attribute": "shots"
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,96 @@
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
+ },
94
+ "count": 3,
95
+ "total_count": 6
96
+ }