belt 0.1.10 → 0.1.11
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/CHANGELOG.md +10 -0
- data/lib/belt/cli/routes_command/route_inference.rb +5 -1
- data/lib/belt/route_dsl.rb +29 -12
- data/lib/belt/version.rb +1 -1
- 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: 68099232d7da2991436a263de28721bfc4e15822116f11a42cd2433588293b59
|
|
4
|
+
data.tar.gz: ba091a54897cfd88b02e2ddf48750ca8a47ca3f4c298b7b4371be799e835550e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e3d77c55c4297f2978486d9d0755ce45fda7f4a8886c372af0b211952502e5f5fde50c0d8881d4d5db39be4c3747a469825dfbd1b5d6f9be1120d441116600a
|
|
7
|
+
data.tar.gz: 7226f0ce500b1d19a7bccf60f9f087573998f3589ae7b41dceba7f35289a71e7e4ea3250269b96b18ef823acff06bbd67916f8d39c1ecb025ce97fbb8288019e
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.1.11
|
|
6
|
+
|
|
7
|
+
### Route DSL
|
|
8
|
+
|
|
9
|
+
- `resources` / `resource` honor `scope path:` (and nested path scopes).
|
|
10
|
+
Example: `scope path: "admin", auth: :cognito { resources :users }` → `/admin/users…` with Cognito auth.
|
|
11
|
+
- Nested `scope path:` segments stack (`a` then `b` → `a/b`) instead of replacing.
|
|
12
|
+
- `scope controller:` is applied to `resources` / `resource` the same way as verb routes.
|
|
13
|
+
- Controller inference for multi-segment resource paths joins segments (`/admin/users` → `admin/users`), matching nested-resource convention.
|
|
14
|
+
|
|
5
15
|
## 0.1.10
|
|
6
16
|
|
|
7
17
|
### Frontend env map
|
|
@@ -14,7 +14,11 @@ module Belt
|
|
|
14
14
|
non_param = segments.reject { |s| s.start_with?(':', '{') }
|
|
15
15
|
return gateway.name if non_param.empty?
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
# Nested resources (/posts/{id}/comments) and scoped resources (/admin/users):
|
|
18
|
+
# join non-param segments → posts/comments, admin/users
|
|
19
|
+
if route.resource? && non_param.length > 1
|
|
20
|
+
return non_param.map { |s| s.gsub('-', '_') }.join('/')
|
|
21
|
+
end
|
|
18
22
|
|
|
19
23
|
# For non-resource routes with a single segment (e.g., post '/signup' in :onboarding),
|
|
20
24
|
# the segment is the action name, not the controller. Use the gateway name as controller.
|
data/lib/belt/route_dsl.rb
CHANGED
|
@@ -174,20 +174,22 @@ module Belt
|
|
|
174
174
|
resource_name = name.to_s
|
|
175
175
|
singular = singularize(resource_name)
|
|
176
176
|
param_name = options[:param] || "#{singular}_id"
|
|
177
|
+
base_path = resource_base_path(resource_name, options)
|
|
178
|
+
options = options.except(:path_prefix)
|
|
177
179
|
options = auto_infer_tables(resource_name, options)
|
|
178
180
|
resource_options = options.merge(route_type: :resources)
|
|
179
181
|
actions = determine_actions(options)
|
|
180
182
|
|
|
181
|
-
add_route(:get,
|
|
182
|
-
add_route(:post,
|
|
183
|
-
add_route(:get, "
|
|
184
|
-
add_route(:put, "
|
|
185
|
-
add_route(:delete, "
|
|
183
|
+
add_route(:get, base_path, resource_options) if actions.include?(:index)
|
|
184
|
+
add_route(:post, base_path, resource_options) if actions.include?(:create)
|
|
185
|
+
add_route(:get, "#{base_path}/{#{param_name}}", resource_options) if actions.include?(:show)
|
|
186
|
+
add_route(:put, "#{base_path}/{#{param_name}}", resource_options) if actions.include?(:update)
|
|
187
|
+
add_route(:delete, "#{base_path}/{#{param_name}}", resource_options) if actions.include?(:destroy)
|
|
186
188
|
|
|
187
189
|
return unless block_given?
|
|
188
190
|
|
|
189
|
-
collection_prefix =
|
|
190
|
-
member_prefix = "
|
|
191
|
+
collection_prefix = base_path
|
|
192
|
+
member_prefix = "#{base_path}/{#{param_name}}"
|
|
191
193
|
resource_tables = Array(options[:tables] || [])
|
|
192
194
|
inherited_tables = (@default_tables + resource_tables).uniq
|
|
193
195
|
inherited_auth = options[:auth] || @default_auth
|
|
@@ -199,17 +201,25 @@ module Belt
|
|
|
199
201
|
|
|
200
202
|
def resource(name, options = {})
|
|
201
203
|
resource_name = name.to_s
|
|
204
|
+
base_path = resource_base_path(resource_name, options)
|
|
205
|
+
options = options.except(:path_prefix)
|
|
202
206
|
actions = determine_actions(options, default: %i[show update destroy])
|
|
203
207
|
resource_options = options.merge(route_type: :resource)
|
|
204
208
|
|
|
205
|
-
add_route(:get,
|
|
206
|
-
add_route(:put,
|
|
207
|
-
add_route(:delete,
|
|
208
|
-
add_route(:post,
|
|
209
|
+
add_route(:get, base_path, resource_options) if actions.include?(:show)
|
|
210
|
+
add_route(:put, base_path, resource_options) if actions.include?(:update)
|
|
211
|
+
add_route(:delete, base_path, resource_options) if actions.include?(:destroy)
|
|
212
|
+
add_route(:post, base_path, resource_options) if actions.include?(:create)
|
|
209
213
|
end
|
|
210
214
|
|
|
211
215
|
private
|
|
212
216
|
|
|
217
|
+
# Builds "/users" or "/admin/users" when path_prefix is set (from scope path:).
|
|
218
|
+
def resource_base_path(resource_name, options)
|
|
219
|
+
prefix = options[:path_prefix].to_s.gsub(%r{^/|/$}, '')
|
|
220
|
+
prefix.empty? ? "/#{resource_name}" : "/#{prefix}/#{resource_name}"
|
|
221
|
+
end
|
|
222
|
+
|
|
213
223
|
def add_route(method, path, options = {})
|
|
214
224
|
lambda_to_use = options[:lambda] || @current_lambda_context || @default_lambda
|
|
215
225
|
route_tables = Array(options[:tables] || [])
|
|
@@ -308,7 +318,11 @@ module Belt
|
|
|
308
318
|
previous_tables = @scope_tables
|
|
309
319
|
previous_controller = @scope_controller
|
|
310
320
|
|
|
311
|
-
|
|
321
|
+
# Nest path segments (Rails-style): scope path: "a" { scope path: "b" } → "a/b"
|
|
322
|
+
if options.key?(:path)
|
|
323
|
+
segment = options[:path].to_s.gsub(%r{^/|/$}, '')
|
|
324
|
+
@scope_prefix = @scope_prefix.to_s.empty? ? segment : "#{@scope_prefix}/#{segment}"
|
|
325
|
+
end
|
|
312
326
|
@scope_module = options[:module] || @scope_module
|
|
313
327
|
@scope_auth = options[:auth] || @scope_auth
|
|
314
328
|
@scope_tables = (@scope_tables + Array(options[:tables] || [])).uniq
|
|
@@ -340,11 +354,13 @@ module Belt
|
|
|
340
354
|
|
|
341
355
|
def resources(name, options = {}, &)
|
|
342
356
|
options = apply_scope_options(options)
|
|
357
|
+
options = options.merge(path_prefix: @scope_prefix) unless @scope_prefix.to_s.empty?
|
|
343
358
|
@gateway.resources(name, options, &)
|
|
344
359
|
end
|
|
345
360
|
|
|
346
361
|
def resource(name, options = {})
|
|
347
362
|
options = apply_scope_options(options)
|
|
363
|
+
options = options.merge(path_prefix: @scope_prefix) unless @scope_prefix.to_s.empty?
|
|
348
364
|
@gateway.resource(name, options)
|
|
349
365
|
end
|
|
350
366
|
|
|
@@ -400,6 +416,7 @@ module Belt
|
|
|
400
416
|
result = options.dup
|
|
401
417
|
result[:auth] ||= @scope_auth if @scope_auth
|
|
402
418
|
result[:lambda] ||= @scope_module if @scope_module
|
|
419
|
+
result[:controller] ||= @scope_controller if @scope_controller
|
|
403
420
|
result[:tables] = (@scope_tables + Array(result[:tables] || [])).uniq if @scope_tables.any? || result[:tables]
|
|
404
421
|
result
|
|
405
422
|
end
|
data/lib/belt/version.rb
CHANGED