toast 0.4.0 → 0.4.1
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.
- data/lib/toast/association.rb +22 -7
- data/lib/toast/engine.rb +0 -1
- data/lib/toast/record.rb +8 -1
- data/lib/toast/resource.rb +2 -2
- data/lib/toast/root_collection.rb +5 -0
- metadata +2 -2
data/lib/toast/association.rb
CHANGED
@@ -39,15 +39,23 @@ module Toast
|
|
39
39
|
def put payload
|
40
40
|
# only for has_one/belongs_to assocs
|
41
41
|
raise MethodNotAllowed if @is_collection
|
42
|
+
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
begin
|
45
|
+
payload = ActiveSupport::JSON.decode(payload)
|
46
|
+
rescue
|
47
|
+
raise PayloadFormatError
|
46
48
|
end
|
47
49
|
|
50
|
+
|
48
51
|
unless payload.is_a? Hash
|
49
52
|
raise PayloadFormatError
|
50
53
|
end
|
54
|
+
|
55
|
+
# update see record
|
56
|
+
if self.media_type != @associate_model.toast_config.media_type
|
57
|
+
raise UnsupportedMediaType
|
58
|
+
end
|
51
59
|
|
52
60
|
# silently ignore all exposed readable, but not writable fields
|
53
61
|
(@associate_model.toast_config.readables - @associate_model.toast_config.writables).each do |rof|
|
@@ -76,16 +84,23 @@ module Toast
|
|
76
84
|
raise UnsupportedMediaType
|
77
85
|
end
|
78
86
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
87
|
+
begin
|
88
|
+
payload = ActiveSupport::JSON.decode(payload)
|
89
|
+
rescue
|
90
|
+
raise PayloadFormatError
|
83
91
|
end
|
84
92
|
|
85
93
|
unless payload.is_a? Hash
|
86
94
|
raise PayloadFormatError
|
87
95
|
end
|
88
96
|
|
97
|
+
|
98
|
+
# silently ignore all exposed readable, but not writable fields
|
99
|
+
(@associate_model.toast_config.readables - @associate_model.toast_config.writables).each do |rof|
|
100
|
+
payload.delete(rof)
|
101
|
+
end
|
102
|
+
|
103
|
+
|
89
104
|
begin
|
90
105
|
record = @record.send(@assoc).create! payload
|
91
106
|
|
data/lib/toast/engine.rb
CHANGED
data/lib/toast/record.rb
CHANGED
@@ -17,14 +17,21 @@ module Toast
|
|
17
17
|
# argument for ActionController#render
|
18
18
|
|
19
19
|
def put payload
|
20
|
+
|
20
21
|
if self.media_type != @model.toast_config.media_type
|
21
22
|
raise UnsupportedMediaType
|
22
23
|
end
|
23
24
|
|
25
|
+
begin
|
26
|
+
payload = ActiveSupport::JSON.decode(payload)
|
27
|
+
rescue
|
28
|
+
raise PayloadFormatError
|
29
|
+
end
|
30
|
+
|
24
31
|
unless payload.is_a? Hash
|
25
32
|
raise PayloadFormatError
|
26
33
|
end
|
27
|
-
|
34
|
+
|
28
35
|
# silently ignore all exposed readable, but not writable fields
|
29
36
|
(@model.toast_config.readables - @model.toast_config.writables).each do |rof|
|
30
37
|
payload.delete(rof)
|
data/lib/toast/resource.rb
CHANGED
@@ -42,7 +42,7 @@ module Toast
|
|
42
42
|
else
|
43
43
|
raise ResourceNotFound
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
rsc.media_type = request.media_type
|
47
47
|
|
48
48
|
rsc
|
@@ -72,7 +72,7 @@ module Toast
|
|
72
72
|
|
73
73
|
case method
|
74
74
|
when "PUT","POST"
|
75
|
-
self.send(method.downcase,
|
75
|
+
self.send(method.downcase, payload)
|
76
76
|
when "DELETE","GET"
|
77
77
|
self.send(method.downcase)
|
78
78
|
else
|