make_restful 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/make_restful/loaders.rb +28 -4
- data/lib/make_restful/version.rb +1 -1
- metadata +2 -2
data/lib/make_restful/loaders.rb
CHANGED
@@ -3,9 +3,29 @@ module MakeRestful::Loaders
|
|
3
3
|
|
4
4
|
included do
|
5
5
|
|
6
|
-
before_filter :
|
7
|
-
|
8
|
-
before_filter :
|
6
|
+
before_filter :load_resource
|
7
|
+
|
8
|
+
before_filter :load_collection, if: ->(c) {
|
9
|
+
|
10
|
+
(
|
11
|
+
instance_loader[c.params[:action].to_sym].blank? &&
|
12
|
+
collection_loader[c.params[:action].to_sym].present?
|
13
|
+
) || (
|
14
|
+
request.method.upcase == 'GET' &&
|
15
|
+
c.params[:action] != 'new' &&
|
16
|
+
c.params[:id].blank?
|
17
|
+
)
|
18
|
+
|
19
|
+
}
|
20
|
+
|
21
|
+
before_filter :load_instance, if: ->(c) {
|
22
|
+
|
23
|
+
instance_loader[c.params[:action].to_sym].present? ||
|
24
|
+
c.params[:id].present?
|
25
|
+
|
26
|
+
}
|
27
|
+
|
28
|
+
before_filter :verify_method!, :verify_format!
|
9
29
|
|
10
30
|
collection do
|
11
31
|
@resource.all
|
@@ -65,13 +85,14 @@ module MakeRestful::Loaders
|
|
65
85
|
|
66
86
|
def collection=(collection)
|
67
87
|
@collection = collection
|
68
|
-
eval
|
88
|
+
eval "@#{resource_name} = @collection"
|
69
89
|
end
|
70
90
|
|
71
91
|
def verify_method!
|
72
92
|
return if allowed_actions.allowed?(params[:action]) || !%w{GET POST PUT PATCH}.include?(request.method)
|
73
93
|
@response = { error: "Method not allowed" }
|
74
94
|
@status = :method_not_allowed
|
95
|
+
@collection, @instance = nil, nil
|
75
96
|
render(load_template: false)
|
76
97
|
end
|
77
98
|
|
@@ -79,6 +100,9 @@ module MakeRestful::Loaders
|
|
79
100
|
return if allowed_formats.allowed?(request.format.symbol)
|
80
101
|
@response = { error: "Format:#{request.format} is unsupported" }
|
81
102
|
@status = :unsupported_media_type
|
103
|
+
@collection, @instance = nil, nil
|
104
|
+
eval "@#{resource_name} = @collection"
|
105
|
+
eval "@#{instance_name} = @instance"
|
82
106
|
render(load_template: false)
|
83
107
|
end
|
84
108
|
|
data/lib/make_restful/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: make_restful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|