rest_framework 0.8.13 → 0.8.14
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/VERSION +1 -1
- data/lib/rest_framework/controller_mixins/base.rb +19 -10
- data/lib/rest_framework/utils.rb +17 -5
- 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: '0528c2ec3d68b9a457b8c35bd00aa8ad7f19d0bb440fe0d75652b8bade7f7312'
|
4
|
+
data.tar.gz: 364a40189c072a0064397e9410c8c8e93b5b9348f478dc8283de3b8786cd8009
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab0cb394bd1528a03d8b1fd7b42d09c77c076ebabfdd8c8b54816187cad2984b1e22db29f26acf3408edb9f2afefc6261248b4833e8ba857265282107ff6af36
|
7
|
+
data.tar.gz: 72d2ae348a3eea1a7a7c7964f08f7ef79286a75b6b3029241ba84e0ea36be1ec6211ce694fc3ce760aa08a2cdcca5474764bd505e92d44dc24b7723a541859f8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.14
|
@@ -60,7 +60,10 @@ module RESTFramework::BaseControllerMixin
|
|
60
60
|
|
61
61
|
# Get a label from a field/column name, titleized and inflected.
|
62
62
|
def get_label(s)
|
63
|
-
return RESTFramework::Utils.inflect(
|
63
|
+
return RESTFramework::Utils.inflect(
|
64
|
+
s.to_s.titleize(keep_id_suffix: true),
|
65
|
+
self.inflect_acronyms,
|
66
|
+
)
|
64
67
|
end
|
65
68
|
|
66
69
|
# Collect actions (including extra actions) metadata for this controller.
|
@@ -71,16 +74,20 @@ module RESTFramework::BaseControllerMixin
|
|
71
74
|
RESTFramework::BUILTIN_ACTIONS.merge(
|
72
75
|
RESTFramework::RRF_BUILTIN_ACTIONS,
|
73
76
|
).each do |action, methods|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
+
next unless self.method_defined?(action)
|
78
|
+
|
79
|
+
actions[action] = {
|
80
|
+
path: "", methods: methods, type: :builtin, metadata: {label: self.get_label(action)}
|
81
|
+
}
|
77
82
|
end
|
78
83
|
|
79
84
|
# Add builtin bulk actions.
|
80
85
|
RESTFramework::RRF_BUILTIN_BULK_ACTIONS.each do |action, methods|
|
81
|
-
|
82
|
-
|
83
|
-
|
86
|
+
next unless self.method_defined?(action)
|
87
|
+
|
88
|
+
actions[action] = {
|
89
|
+
path: "", methods: methods, type: :builtin, metadata: {label: self.get_label(action)}
|
90
|
+
}
|
84
91
|
end
|
85
92
|
|
86
93
|
# Add extra actions.
|
@@ -97,9 +104,11 @@ module RESTFramework::BaseControllerMixin
|
|
97
104
|
|
98
105
|
# Start with builtin actions.
|
99
106
|
RESTFramework::BUILTIN_MEMBER_ACTIONS.each do |action, methods|
|
100
|
-
|
101
|
-
|
102
|
-
|
107
|
+
next unless self.method_defined?(action)
|
108
|
+
|
109
|
+
actions[action] = {
|
110
|
+
path: "", methods: methods, type: :builtin, metadata: {label: self.get_label(action)}
|
111
|
+
}
|
103
112
|
end
|
104
113
|
|
105
114
|
# Add extra actions.
|
data/lib/rest_framework/utils.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module RESTFramework::Utils
|
2
|
-
|
2
|
+
HTTP_VERB_ORDERING = %w(GET POST PUT PATCH DELETE OPTIONS HEAD)
|
3
3
|
|
4
4
|
# Convert `extra_actions` hash to a consistent format: `{path:, methods:, kwargs:}`, and
|
5
5
|
# additional metadata fields.
|
@@ -8,6 +8,7 @@ module RESTFramework::Utils
|
|
8
8
|
def self.parse_extra_actions(extra_actions, controller: nil)
|
9
9
|
return (extra_actions || {}).map { |k, v|
|
10
10
|
path = k
|
11
|
+
metadata = {}
|
11
12
|
|
12
13
|
# Convert structure to path/methods/kwargs.
|
13
14
|
if v.is_a?(Hash) # Allow kwargs to be used to define path differently from the key.
|
@@ -39,14 +40,19 @@ module RESTFramework::Utils
|
|
39
40
|
methods = v
|
40
41
|
end
|
41
42
|
|
43
|
+
# Insert action label if it's not provided.
|
44
|
+
if controller
|
45
|
+
metadata[:label] ||= controller.get_label(k)
|
46
|
+
end
|
47
|
+
|
42
48
|
next [
|
43
49
|
k,
|
44
50
|
{
|
45
51
|
path: path,
|
46
52
|
methods: methods,
|
47
53
|
kwargs: kwargs,
|
48
|
-
metadata: metadata.presence,
|
49
54
|
type: :extra,
|
55
|
+
metadata: metadata.presence,
|
50
56
|
}.compact,
|
51
57
|
]
|
52
58
|
}.to_h
|
@@ -119,9 +125,15 @@ module RESTFramework::Utils
|
|
119
125
|
_levels: levels,
|
120
126
|
}
|
121
127
|
}.sort_by { |r|
|
122
|
-
|
123
|
-
|
124
|
-
|
128
|
+
[
|
129
|
+
# Sort by levels first, so routes matching closely with current request show first.
|
130
|
+
r[:_levels],
|
131
|
+
# Then match by path, but manually sort ':' to the end using knowledge that Ruby sorts the
|
132
|
+
# pipe character '|' after alphanumerics.
|
133
|
+
r[:path].tr(":", "|"),
|
134
|
+
# Finally, match by HTTP verb.
|
135
|
+
HTTP_VERB_ORDERING.index(r[:verb]) || 99,
|
136
|
+
]
|
125
137
|
}.group_by { |r| r[:controller] }.sort_by { |c, _r|
|
126
138
|
# Sort the controller groups by current controller first, then alphanumerically.
|
127
139
|
[request.params[:controller] == c ? 0 : 1, c]
|