rest_framework 0.2.3 → 0.2.4
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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/rest_framework/VERSION_STAMP +1 -1
- data/lib/rest_framework/routers.rb +25 -42
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d9ce4741f59e6f68bfa18bc2e6c11202c91fbe251eeaa5562f8f718e6e8afaa
|
4
|
+
data.tar.gz: 652ad42a8d0bad99e552af9117112df707e67d4c1e6dd2dd983e7925933fcab6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26036468d40ccc77a203981ba442265ef82c7a991fee800ee3d7925d96d09a696f3db06930e8252c49cf63e86d2aee2fd121a735e5e06609585299ff984d6992
|
7
|
+
data.tar.gz: 3c53d8eed996e380ab3390acfde7a3cef262d38a1355d0016aa6d8129b8e329c99003c0181ec1602f5bb1ba8869355e6b1eb0ff366d8b814ff83f6bb3c9cbf4d
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[](https://badge.fury.io/rb/rest_framework)
|
4
4
|
[](https://travis-ci.org/gregschmit/rails-rest-framework)
|
5
5
|
[](https://coveralls.io/github/gregschmit/rails-rest-framework?branch=master)
|
6
|
+
[](https://codeclimate.com/github/gregschmit/rails-rest-framework/maintainability)
|
6
7
|
|
7
8
|
A framework for DRY RESTful APIs in Ruby on Rails.
|
8
9
|
|
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
@@ -6,7 +6,7 @@ module ActionDispatch::Routing
|
|
6
6
|
# Internal helper to take extra_actions hash and convert to a consistent format.
|
7
7
|
protected def _parse_extra_actions(extra_actions)
|
8
8
|
return (extra_actions || {}).map do |k,v|
|
9
|
-
kwargs = {}
|
9
|
+
kwargs = {action: k}
|
10
10
|
path = k
|
11
11
|
|
12
12
|
# Convert structure to path/methods/kwargs.
|
@@ -25,11 +25,6 @@ module ActionDispatch::Routing
|
|
25
25
|
path = v.delete(:path)
|
26
26
|
end
|
27
27
|
|
28
|
-
# Set the action to be the action key unless it's already defined.
|
29
|
-
if !kwargs[:action]
|
30
|
-
kwargs[:action] = k
|
31
|
-
end
|
32
|
-
|
33
28
|
# Pass any further kwargs to the underlying Rails interface.
|
34
29
|
kwargs = kwargs.merge(v)
|
35
30
|
elsif v.is_a?(Symbol) || v.is_a?(String)
|
@@ -77,6 +72,16 @@ module ActionDispatch::Routing
|
|
77
72
|
return controller
|
78
73
|
end
|
79
74
|
|
75
|
+
# Interal interface for routing extra actions.
|
76
|
+
protected def _route_extra_actions(actions, &block)
|
77
|
+
actions.each do |action_config|
|
78
|
+
action_config[:methods].each do |m|
|
79
|
+
public_send(m, action_config[:path], **action_config[:kwargs])
|
80
|
+
end
|
81
|
+
yield if block_given?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
80
85
|
# Internal core implementation of the `rest_resource(s)` router, both singular and plural.
|
81
86
|
# @param default_singular [Boolean] the default plurality of the resource if the plurality is
|
82
87
|
# not otherwise defined by the controller
|
@@ -105,28 +110,20 @@ module ActionDispatch::Routing
|
|
105
110
|
end
|
106
111
|
resource_method = singular ? :resource : :resources
|
107
112
|
|
108
|
-
#
|
113
|
+
# Call either `resource` or `resources`, passing appropriate modifiers.
|
109
114
|
skip_undefined = kwargs.delete(:skip_undefined) || true
|
110
115
|
skip = controller_class.get_skip_actions(skip_undefined: skip_undefined)
|
111
116
|
public_send(resource_method, name, except: skip, **kwargs) do
|
112
117
|
if controller_class.respond_to?(:extra_member_actions)
|
113
118
|
member do
|
114
119
|
actions = self._parse_extra_actions(controller_class.extra_member_actions)
|
115
|
-
actions
|
116
|
-
action_config[:methods].each do |m|
|
117
|
-
public_send(m, action_config[:path], **action_config[:kwargs])
|
118
|
-
end
|
119
|
-
end
|
120
|
+
_route_extra_actions(actions)
|
120
121
|
end
|
121
122
|
end
|
122
123
|
|
123
124
|
collection do
|
124
125
|
actions = self._parse_extra_actions(controller_class.extra_actions)
|
125
|
-
actions
|
126
|
-
action_config[:methods].each do |m|
|
127
|
-
public_send(m, action_config[:path], **action_config[:kwargs])
|
128
|
-
end
|
129
|
-
end
|
126
|
+
_route_extra_actions(actions)
|
130
127
|
end
|
131
128
|
|
132
129
|
yield if block_given?
|
@@ -150,6 +147,7 @@ module ActionDispatch::Routing
|
|
150
147
|
# Route a controller without the default resourceful paths.
|
151
148
|
def rest_route(name=nil, **kwargs, &block)
|
152
149
|
controller = kwargs.delete(:controller) || name
|
150
|
+
route_root_to = kwargs.delete(:route_root_to)
|
153
151
|
if controller.is_a?(Class)
|
154
152
|
controller_class = controller
|
155
153
|
else
|
@@ -162,42 +160,27 @@ module ActionDispatch::Routing
|
|
162
160
|
# Route actions using the resourceful router, but skip all builtin actions.
|
163
161
|
actions = self._parse_extra_actions(controller_class.extra_actions)
|
164
162
|
public_send(:resource, name, only: [], **kwargs) do
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
169
|
-
yield if block_given?
|
163
|
+
# Route a root for this resource.
|
164
|
+
if route_root_to
|
165
|
+
get '', action: route_root_to
|
170
166
|
end
|
167
|
+
|
168
|
+
_route_extra_actions(actions, &block)
|
171
169
|
end
|
172
170
|
end
|
173
171
|
|
174
172
|
# Route a controller's `#root` to '/' in the current scope/namespace, along with other actions.
|
175
|
-
# @param name [Symbol] the snake_case name of the controller
|
176
173
|
def rest_root(name=nil, **kwargs, &block)
|
177
174
|
# By default, use RootController#root.
|
178
175
|
root_action = kwargs.delete(:action) || :root
|
179
176
|
controller = kwargs.delete(:controller) || name || :root
|
180
177
|
|
181
|
-
#
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
controller_class = self._get_controller_class(controller, pluralize: false)
|
186
|
-
actions = self._parse_extra_actions(controller_class.extra_actions)
|
187
|
-
actions.each do |action_config|
|
188
|
-
# Add :action unless kwargs defines it.
|
189
|
-
unless action_config[:kwargs].key?(:action)
|
190
|
-
action_config[:kwargs][:action] = action_config[:path]
|
191
|
-
end
|
178
|
+
# Remove path if name is nil (routing to the root of current namespace).
|
179
|
+
unless name
|
180
|
+
kwargs[:path] = ''
|
181
|
+
end
|
192
182
|
|
193
|
-
|
194
|
-
public_send(
|
195
|
-
m,
|
196
|
-
File.join(name.to_s, action_config[:path].to_s),
|
197
|
-
controller: controller,
|
198
|
-
**action_config[:kwargs],
|
199
|
-
)
|
200
|
-
end
|
183
|
+
return rest_route(controller, route_root_to: root_action, **kwargs) do
|
201
184
|
yield if block_given?
|
202
185
|
end
|
203
186
|
end
|