toast 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controller/toast_controller.rb +1 -0
- data/lib/toast/collection.rb +16 -9
- data/lib/toast/config_dsl.rb +12 -0
- data/lib/toast/record.rb +12 -5
- data/lib/toast/version.rb +1 -1
- metadata +20 -7
data/lib/toast/collection.rb
CHANGED
@@ -28,16 +28,16 @@ module Toast
|
|
28
28
|
unless @model_or_relation.respond_to?(@collection)
|
29
29
|
raise "Toast Error: Cannot find class method '#{@collection}' of model '#{@model_or_relation}', which is configured in 'acts_as_resource > collections'."
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# FIXME: This is a lot of hallooballoo to check if the #send
|
33
33
|
# will be successful, but if it's not checked the error
|
34
34
|
# message is not helpful to find the error.
|
35
35
|
|
36
|
-
records = if @config_out.pass_params_to.include?(@collection)
|
37
|
-
if @target_model.method(@collection).arity != 1
|
36
|
+
records = if @config_out.pass_params_to.include?(@collection)
|
37
|
+
if @target_model.method(@collection).arity**2 != 1
|
38
38
|
raise "Toast Error: Class method '#{@collection}' of model '#{@target_model}' must accept one parameter, as configured by 'acts_as_resource > pass_params_to'."
|
39
39
|
end
|
40
|
-
# fetch results
|
40
|
+
# fetch results
|
41
41
|
@model_or_relation.send(@collection, @params)
|
42
42
|
|
43
43
|
else
|
@@ -78,14 +78,11 @@ module Toast
|
|
78
78
|
def post payload, media_type
|
79
79
|
raise MethodNotAllowed unless @config_in.postable?
|
80
80
|
|
81
|
+
|
81
82
|
if media_type != @config_in.media_type
|
82
83
|
raise UnsupportedMediaType
|
83
84
|
end
|
84
85
|
|
85
|
-
if @collection != "all"
|
86
|
-
raise MethodNotAllowed
|
87
|
-
end
|
88
|
-
|
89
86
|
begin
|
90
87
|
payload = ActiveSupport::JSON.decode(payload)
|
91
88
|
rescue
|
@@ -100,8 +97,18 @@ module Toast
|
|
100
97
|
payload.delete(rof)
|
101
98
|
end
|
102
99
|
|
100
|
+
|
103
101
|
begin
|
104
|
-
|
102
|
+
|
103
|
+
if @collection != "all"
|
104
|
+
# post on scope?
|
105
|
+
record = @model_or_relation.create! payload do |obj|
|
106
|
+
hook = @config_in.before_scoped_create[@collection]
|
107
|
+
obj.send(hook) if hook
|
108
|
+
end
|
109
|
+
else
|
110
|
+
record = @model_or_relation.create! payload
|
111
|
+
end
|
105
112
|
|
106
113
|
{
|
107
114
|
:json => record.represent( @config_out.exposed_attributes,
|
data/lib/toast/config_dsl.rb
CHANGED
@@ -14,6 +14,7 @@ module Toast
|
|
14
14
|
@deletable = false
|
15
15
|
@postable = false
|
16
16
|
@pass_params_to = []
|
17
|
+
@before_scoped_create = {}
|
17
18
|
@in_collection = ConfigDSL::InCollection.new model, self
|
18
19
|
@media_type = "application/json"
|
19
20
|
|
@@ -76,6 +77,17 @@ module Toast
|
|
76
77
|
self.pass_params_to = arg
|
77
78
|
end
|
78
79
|
|
80
|
+
def before_scoped_create= arg
|
81
|
+
for key in arg.keys
|
82
|
+
@before_scoped_create[key.to_s] = arg[key].to_sym
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def before_scoped_create arg={}
|
87
|
+
return(@before_scoped_create) if arg.empty?
|
88
|
+
self.before_scoped_create = arg
|
89
|
+
end
|
90
|
+
|
79
91
|
def collections= collections=[]
|
80
92
|
@collections = ConfigDSL.sanitize(collections, "collections")
|
81
93
|
end
|
data/lib/toast/record.rb
CHANGED
@@ -86,11 +86,18 @@ module Toast
|
|
86
86
|
def delete
|
87
87
|
raise MethodNotAllowed unless @config_out.deletable?
|
88
88
|
|
89
|
-
@record.destroy
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
if @record.destroy
|
90
|
+
{
|
91
|
+
:nothing => true,
|
92
|
+
:status => :ok
|
93
|
+
}
|
94
|
+
else
|
95
|
+
{
|
96
|
+
:nothing => true,
|
97
|
+
:status => :conflict
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
94
101
|
end
|
95
102
|
|
96
103
|
def link l
|
data/lib/toast/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 7
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
9
|
+
- 2
|
10
|
+
version: 0.7.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- "robokopp (Robert Anni\xC3\xA9s)"
|
@@ -14,16 +15,17 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2012-07-
|
18
|
-
default_executable:
|
18
|
+
date: 2012-07-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: shoulda
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
27
29
|
segments:
|
28
30
|
- 0
|
29
31
|
version: "0"
|
@@ -33,9 +35,11 @@ dependencies:
|
|
33
35
|
name: rails
|
34
36
|
prerelease: false
|
35
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
36
39
|
requirements:
|
37
40
|
- - ">="
|
38
41
|
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
39
43
|
segments:
|
40
44
|
- 3
|
41
45
|
- 1
|
@@ -47,9 +51,11 @@ dependencies:
|
|
47
51
|
name: blockenspiel
|
48
52
|
prerelease: false
|
49
53
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
50
55
|
requirements:
|
51
56
|
- - ~>
|
52
57
|
- !ruby/object:Gem::Version
|
58
|
+
hash: 11
|
53
59
|
segments:
|
54
60
|
- 0
|
55
61
|
- 4
|
@@ -61,9 +67,11 @@ dependencies:
|
|
61
67
|
name: rack-accept-media-types
|
62
68
|
prerelease: false
|
63
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
64
71
|
requirements:
|
65
72
|
- - ~>
|
66
73
|
- !ruby/object:Gem::Version
|
74
|
+
hash: 25
|
67
75
|
segments:
|
68
76
|
- 0
|
69
77
|
- 9
|
@@ -74,9 +82,11 @@ dependencies:
|
|
74
82
|
name: ffaker
|
75
83
|
prerelease: false
|
76
84
|
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
77
86
|
requirements:
|
78
87
|
- - ">="
|
79
88
|
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
80
90
|
segments:
|
81
91
|
- 0
|
82
92
|
version: "0"
|
@@ -108,7 +118,6 @@ files:
|
|
108
118
|
- lib/toast/single.rb
|
109
119
|
- lib/toast/scoped_association.rb
|
110
120
|
- README.md
|
111
|
-
has_rdoc: true
|
112
121
|
homepage: https://github.com/robokopp/toast
|
113
122
|
licenses: []
|
114
123
|
|
@@ -118,23 +127,27 @@ rdoc_options: []
|
|
118
127
|
require_paths:
|
119
128
|
- lib
|
120
129
|
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
121
131
|
requirements:
|
122
132
|
- - ">="
|
123
133
|
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
124
135
|
segments:
|
125
136
|
- 0
|
126
137
|
version: "0"
|
127
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
128
140
|
requirements:
|
129
141
|
- - ">="
|
130
142
|
- !ruby/object:Gem::Version
|
143
|
+
hash: 3
|
131
144
|
segments:
|
132
145
|
- 0
|
133
146
|
version: "0"
|
134
147
|
requirements: []
|
135
148
|
|
136
149
|
rubyforge_project:
|
137
|
-
rubygems_version: 1.
|
150
|
+
rubygems_version: 1.8.24
|
138
151
|
signing_key:
|
139
152
|
specification_version: 3
|
140
153
|
summary: Toast adds a RESTful interface to ActiveRecord models in Ruby on Rails.
|