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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e6db6727ad85819540fc9d5977205f553523fe2f1f4431c985193ffd47f27bc
4
- data.tar.gz: cddc4ff0d75aa6d2856d1c6bde681d38f955675a9c11b3853eef617e1abfad8b
3
+ metadata.gz: '0528c2ec3d68b9a457b8c35bd00aa8ad7f19d0bb440fe0d75652b8bade7f7312'
4
+ data.tar.gz: 364a40189c072a0064397e9410c8c8e93b5b9348f478dc8283de3b8786cd8009
5
5
  SHA512:
6
- metadata.gz: 86384e43ffa97406feb6a9760cb9ca425cbc725cb41324fe21a688216cf075ccdf2e27b682231dd11d4d7507740a8645eb66c4076df165d69da4a56d87d11efd
7
- data.tar.gz: 7b22d9730b039452065db1e27d580ee1db4105861f323bd2800906a8c5197ed4d8cf76bb532c193dd3ab3255d491faeb04cbf47a677acbb1dbb46bfc0b6f2fc3
6
+ metadata.gz: ab0cb394bd1528a03d8b1fd7b42d09c77c076ebabfdd8c8b54816187cad2984b1e22db29f26acf3408edb9f2afefc6261248b4833e8ba857265282107ff6af36
7
+ data.tar.gz: 72d2ae348a3eea1a7a7c7964f08f7ef79286a75b6b3029241ba84e0ea36be1ec6211ce694fc3ce760aa08a2cdcca5474764bd505e92d44dc24b7723a541859f8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.13
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(s.titleize(keep_id_suffix: true), self.inflect_acronyms)
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
- if self.method_defined?(action)
75
- actions[action] = {path: "", methods: methods, type: :builtin}
76
- end
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
- if self.method_defined?(action)
82
- actions[action] = {path: "", methods: methods, type: :builtin}
83
- end
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
- if self.method_defined?(action)
101
- actions[action] = {path: "", methods: methods, type: :builtin}
102
- end
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.
@@ -1,5 +1,5 @@
1
1
  module RESTFramework::Utils
2
- HTTP_METHOD_ORDERING = %w(GET POST PUT PATCH DELETE OPTIONS HEAD)
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
- # Sort by levels first, so the routes matching closely with current request show first, then
123
- # by the path, and finally by the HTTP verb.
124
- [r[:_levels], r[:path], HTTP_METHOD_ORDERING.index(r[:verb]) || 99]
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.13
4
+ version: 0.8.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory N. Schmit