rest_framework 0.8.13 → 0.8.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rest_framework/controller_mixins/base.rb +19 -10
- data/lib/rest_framework/controller_mixins/models.rb +3 -1
- data/lib/rest_framework/utils.rb +17 -5
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36036d097655858aedddc79945d798ae9e8c8dec48ee1e8c59e06e98b9bdf694
|
4
|
+
data.tar.gz: fc9ced23a919bd6c0528f1b91999e89ca959ce433c0ef99938a46abc46574ca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dea10ba8f4d5cc9cc4fe186b1101823eb7268fe3543ce4dfd850d33d477cb3fe7ba413138ab0b3ade2490e4a3b5bb1bc8880d8ad41296ada615e0e732618ea5
|
7
|
+
data.tar.gz: 3071fc01e29b932141f70301dae07de686c691416863906b09815d89f7cc6c50e1c4351582a94a5ec1fd67fecdd028808bf2f4efd3e57113790cc9f9f2baf8fc
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.15
|
@@ -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.
|
@@ -94,7 +94,7 @@ module RESTFramework::BaseModelControllerMixin
|
|
94
94
|
# array. This should always return an array of strings, no symbols, and possibly `nil` (only if
|
95
95
|
# `fallback` is false).
|
96
96
|
def get_fields(input_fields: nil, fallback: true)
|
97
|
-
input_fields ||= self.fields
|
97
|
+
input_fields ||= self.fields if fallback
|
98
98
|
|
99
99
|
# If fields is a hash, then parse it.
|
100
100
|
if input_fields.is_a?(Hash)
|
@@ -107,6 +107,8 @@ module RESTFramework::BaseModelControllerMixin
|
|
107
107
|
return model ? RESTFramework::Utils.fields_for(
|
108
108
|
model, exclude_associations: self.exclude_associations
|
109
109
|
) : []
|
110
|
+
elsif input_fields
|
111
|
+
input_fields = input_fields.map(&:to_s)
|
110
112
|
end
|
111
113
|
|
112
114
|
return input_fields
|
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]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory N. Schmit
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -62,7 +62,7 @@ licenses:
|
|
62
62
|
metadata:
|
63
63
|
homepage_uri: https://rails-rest-framework.com
|
64
64
|
source_code_uri: https://github.com/gregschmit/rails-rest-framework
|
65
|
-
post_install_message:
|
65
|
+
post_install_message:
|
66
66
|
rdoc_options: []
|
67
67
|
require_paths:
|
68
68
|
- lib
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubygems_version: 3.2.33
|
82
|
-
signing_key:
|
82
|
+
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: A framework for DRY RESTful APIs in Ruby on Rails.
|
85
85
|
test_files: []
|