rest_framework 0.8.13 → 0.8.15

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: 36036d097655858aedddc79945d798ae9e8c8dec48ee1e8c59e06e98b9bdf694
4
+ data.tar.gz: fc9ced23a919bd6c0528f1b91999e89ca959ce433c0ef99938a46abc46574ca9
5
5
  SHA512:
6
- metadata.gz: 86384e43ffa97406feb6a9760cb9ca425cbc725cb41324fe21a688216cf075ccdf2e27b682231dd11d4d7507740a8645eb66c4076df165d69da4a56d87d11efd
7
- data.tar.gz: 7b22d9730b039452065db1e27d580ee1db4105861f323bd2800906a8c5197ed4d8cf76bb532c193dd3ab3255d491faeb04cbf47a677acbb1dbb46bfc0b6f2fc3
6
+ metadata.gz: 3dea10ba8f4d5cc9cc4fe186b1101823eb7268fe3543ce4dfd850d33d477cb3fe7ba413138ab0b3ade2490e4a3b5bb1bc8880d8ad41296ada615e0e732618ea5
7
+ data.tar.gz: 3071fc01e29b932141f70301dae07de686c691416863906b09815d89f7cc6c50e1c4351582a94a5ec1fd67fecdd028808bf2f4efd3e57113790cc9f9f2baf8fc
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.13
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(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.
@@ -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&.map(&:to_s) if fallback
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
@@ -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,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.13
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-02 00:00:00.000000000 Z
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: []