belt 0.4.3 → 0.4.4

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: f2a6059e3ba3ce67327476626815d9a1b61b441836877277c44d04978dfa2727
4
- data.tar.gz: d714bba5f18070ed1504e33f473a9fd2497019da7fe7c5609b9d97e4676d70ee
3
+ metadata.gz: 8a4efb62a37845ad3c311558cebdd71fcf74ba7ae31870f3c2728e286dc33a72
4
+ data.tar.gz: 8278be1ba1c44b6d355d00963ca1d33c401749b0af584a4cb5c07f6ae25bca54
5
5
  SHA512:
6
- metadata.gz: d6feaddb7cb071ee7cb75427544d2d32b65ddf9354c3fa08461a67247485fdd6adddf986d93d0ee3fa778ab491136ca14395e5b6dc67fc918eb19b748b8a4214
7
- data.tar.gz: 56b99bafbc94e4abcb7fa64cb3ca7b1744591c17c84afea3fe1cab07bb1cbeffe6c76f7af5b6c6f19a51bebffecba10091a70125de012f885709e417cf817bd2
6
+ metadata.gz: b3d9d4782cd23143c6674b674780072784077105eeef396ec04d55b194ef102c643c5cd646311cdf024983c1e1a7f70407bea5bb2e0cb5261938e58d0dcceb87
7
+ data.tar.gz: a7e6cc11a4e2625b135cf967af4f614dcaa21fd7ee7b8cfcbea42bd68eea8976368a6392e257f2f229f8a6e9673414546044628cefa1f4fe0d6a2d9042b0b90f
data/CHANGELOG.md CHANGED
@@ -18,8 +18,23 @@
18
18
 
19
19
  ## Unreleased
20
20
 
21
+ ## 0.4.4
22
+
21
23
  ### Bug Fix
22
24
 
25
+ - **Gateway-level `scope path:` with a param segment no longer emits malformed paths.**
26
+ A gateway-level `scope path: 'accounts/:account_id'` used to leak the raw Rails-style
27
+ `:account_id` segment straight into route paths (`/accounts/:account_id/changes`)
28
+ instead of the API Gateway `{account_id}` form, and — worse — a bare-param scope with a
29
+ path that didn't start with `/` (e.g. `get 'summary'`) produced fused garbage like
30
+ `/accounts/{account_idsummary}`. It also folded the param segment into the derived
31
+ controller module (`accounts/:account_id/changes`). Now `build_path` joins the scope
32
+ prefix and route path with exactly one `/` and normalizes `:param` → `{param}`, and
33
+ the controller module is derived only from the scope's *static* segments (matching
34
+ Rails, where `scope path:` shapes the URL, not the module). Static-only scopes
35
+ (`scope path: 'admin'` → `admin/users`) are unchanged. A scope nested inside a
36
+ `resources` block was already fine; only the gateway-level case was broken.
37
+
23
38
  - **`belt setup tables` no longer silently clobbers hand-added tables/GSIs.**
24
39
  Regenerating `dynamodb.tf` is a full overwrite from `lambda/models/*.rb`, so a
25
40
  table or `global_secondary_index` added straight into the `.tf` file — one the
@@ -788,14 +788,25 @@ module Belt
788
788
  private
789
789
 
790
790
  def build_path(path)
791
- @scope_prefix.empty? ? path : "/#{@scope_prefix}#{path}"
791
+ path = path.to_s
792
+ sep = @scope_prefix.empty? || path.empty? || path.start_with?('/') ? '' : '/'
793
+ prefix = @scope_prefix.empty? ? '' : "/#{@scope_prefix}"
794
+ # Normalize Rails-style `:param` → API Gateway `{param}` so a gateway-level
795
+ # `scope path:` with a param (e.g. "accounts/:account_id") emits valid paths.
796
+ "#{prefix}#{sep}#{path}".gsub(/:([a-zA-Z_]\w*)/) { "{#{::Regexp.last_match(1)}}" }
797
+ end
798
+
799
+ # Strip param segments (`:param` / `{param}`) from a scope prefix before using it
800
+ # as a controller module: `scope path:` affects the URL, not the module.
801
+ def controller_module_from_prefix(prefix)
802
+ prefix.to_s.split('/').reject { |s| s.empty? || s.start_with?(':', '{') }.join('/')
792
803
  end
793
804
 
794
805
  def determine_scoped_controller(resource_name)
795
806
  if @scope_module && !@scope_module.empty?
796
807
  "#{@scope_module}/#{resource_name}"
797
- elsif !@scope_prefix.empty?
798
- "#{@scope_prefix}/#{resource_name}"
808
+ elsif !@scope_prefix.empty? && !(mod = controller_module_from_prefix(@scope_prefix)).empty?
809
+ "#{mod}/#{resource_name}"
799
810
  else
800
811
  resource_name
801
812
  end
data/lib/belt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Belt
4
- VERSION = '0.4.3'
4
+ VERSION = '0.4.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla