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.
@@ -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
- # update see record
44
- if self.media_type != @associate_model.toast_config.media_type
45
- raise UnsupportedMediaType
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
- # silently ignore all exposed readable, but not writable fields
81
- (@associate_model.toast_config.readables - @associate_model.toast_config.writables).each do |rof|
82
- payload.delete(rof)
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
@@ -2,7 +2,6 @@ require 'toast/active_record_extensions.rb'
2
2
  require 'toast/resource.rb'
3
3
  require 'toast/root_collection'
4
4
  require 'toast/association'
5
- require 'toast/attribute'
6
5
  require 'toast/record'
7
6
  require 'toast/single'
8
7
 
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)
@@ -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, ActiveSupport::JSON.decode(payload))
75
+ self.send(method.downcase, payload)
76
76
  when "DELETE","GET"
77
77
  self.send(method.downcase)
78
78
  else
@@ -61,6 +61,11 @@ module Toast
61
61
  raise UnsupportedMediaType
62
62
  end
63
63
 
64
+ begin
65
+ payload = ActiveSupport::JSON.decode(payload)
66
+ rescue
67
+ raise PayloadFormatError
68
+ end
64
69
  unless payload.is_a? Hash
65
70
  raise PayloadFormatError
66
71
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Robert Annies