belt 0.3.35 → 0.3.37

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: b880627c5b6f7d73fe1957bfeff61f0b601d8520f3b57053193bef5891b2ef9c
4
- data.tar.gz: 2069b8d810cc8bf3ef0ec8cd4c15b2baf95719bc7f546875b3dc0987e26ca8d3
3
+ metadata.gz: '0308512f255c22a7fbc31ff42a20947ee8c155c4c9ceaea3a4824a1e5a50c618'
4
+ data.tar.gz: e071128ae46f66256e4f52c5a0b3eb096e49faf2a0cde9e6c3d962c6ed54af93
5
5
  SHA512:
6
- metadata.gz: 1e2583c0ec4320dc90e00a72c48b8f04d208cfc0f4dc561306b6630495456ca9cf81c18d396804f4bbf9267ac6512238187ac864e5af6c1e2559c2a2bfccf89b
7
- data.tar.gz: 9cf50f3894ef696c965183d9b45f572cc4cc245817e9b6f30ae3fdefe67613b0b3ba762f78bb34dc68587c22fc3f01eb1cbf44c5c8a817c3cb6d26aa5dd24d15
6
+ metadata.gz: ec4a7be24ec7cb6961ed6c06cbc7690eb05a92406cf10cedf8760ef5cde8d464bd062652524ca74e41fdd6045f495b77e1c252823d1d18e14090ed986073f1ac
7
+ data.tar.gz: '08f0980d98b9c868c7e53c23236acc3c72be619f3b361dea0a1520a3d5e71549ad95758d7cc8cdbdd21186dfcbd7f6e7d7acff822b1b12d00225d2c35711f6e3'
@@ -148,7 +148,13 @@ module Belt
148
148
  # -- keyword options for destroy flags
149
149
  def initialize(generator, name, fields, force: false, skip_terraform: false, full: false, frontend_name: nil)
150
150
  @generator = generator
151
- @name = name&.downcase&.gsub(/[^a-z0-9_]/, '_')
151
+ # Environment names preserve hyphens (matching `belt g environment`);
152
+ # other generators normalize to underscores for valid Ruby identifiers.
153
+ @name = if generator == 'environment'
154
+ name&.downcase&.gsub(/[^a-z0-9_-]/, '')
155
+ else
156
+ name&.downcase&.gsub(/[^a-z0-9_]/, '_')
157
+ end
152
158
  @fields = fields
153
159
  @force = force
154
160
  @skip_terraform = skip_terraform
@@ -4,8 +4,10 @@ require 'shellwords'
4
4
  require 'open3'
5
5
  require_relative 'app_detection'
6
6
  require_relative 'env_resolver'
7
+ require_relative 'environment_config'
7
8
  require_relative 'frontend_env_map'
8
9
  require_relative 'frontend_registry'
10
+ require_relative 'terraform_command'
9
11
 
10
12
  module Belt
11
13
  module CLI
@@ -54,11 +56,13 @@ module Belt
54
56
  def initialize(env, frontend: nil)
55
57
  @env = env
56
58
  @app_name = detect_app_name
57
- @env_dir = "infrastructure/#{@env}"
59
+ @infra_dir = TerraformCommand.find_infrastructure_dir || 'infrastructure'
60
+ @env_dir = File.join(@infra_dir, @env)
58
61
  @frontend = frontend || FrontendRegistry.new.resolve!
59
62
  end
60
63
 
61
64
  def run
65
+ load_and_apply_env_config!
62
66
  validate!
63
67
  puts "━━━ #{@frontend.label} (#{@frontend.path}/) ━━━"
64
68
  build_frontend
@@ -71,6 +75,12 @@ module Belt
71
75
 
72
76
  private
73
77
 
78
+ def load_and_apply_env_config!
79
+ env_config = EnvironmentConfig.load(@env, infra_dir: @infra_dir)
80
+ env_config.apply!
81
+ puts " 🔑 Using AWS profile: #{env_config.aws_profile}" if env_config.aws_profile?
82
+ end
83
+
74
84
  def validate!
75
85
  unless Dir.exist?(@frontend.path)
76
86
  abort "Error: No #{@frontend.path}/ directory found. " \
@@ -96,7 +96,8 @@ module Belt
96
96
 
97
97
  %i[get post put delete patch].each do |method|
98
98
  define_method(method) do |path, options = {}|
99
- full_path = options[:on] == :collection ? "#{@collection_prefix}#{path}" : "#{@prefix}#{path}"
99
+ base = options[:on] == :collection ? @collection_prefix : @prefix
100
+ full_path = join_path(base, path)
100
101
  options = merge_inherited_options(options)
101
102
  route_options = options.except(:on)
102
103
  @gateway.send(:add_route, method, full_path, route_options)
@@ -105,6 +106,15 @@ module Belt
105
106
 
106
107
  private
107
108
 
109
+ # Join a base path with a relative path, ensuring exactly one `/` separator.
110
+ def join_path(base, path)
111
+ path = path.to_s
112
+ return base if path.empty?
113
+ return "#{base}#{path}" if path.start_with?('/')
114
+
115
+ "#{base}/#{path}"
116
+ end
117
+
108
118
  def add_nested_resource_routes(resource_name, param_name, resource_options, actions)
109
119
  if actions.include?(:index)
110
120
  @gateway.send(:add_route, :get, "#{@prefix}/#{resource_name}",
@@ -165,7 +175,7 @@ module Belt
165
175
 
166
176
  %i[get post put delete patch].each do |method|
167
177
  define_method(method) do |path, options = {}|
168
- full_path = "#{@prefix}#{path}"
178
+ full_path = join_path(@prefix, path)
169
179
  options = merge_inherited_options(options)
170
180
  @gateway.send(:add_route, method, full_path, options)
171
181
  end
@@ -173,6 +183,15 @@ module Belt
173
183
 
174
184
  private
175
185
 
186
+ # Join a base path with a relative path, ensuring exactly one `/` separator.
187
+ def join_path(base, path)
188
+ path = path.to_s
189
+ return base if path.empty?
190
+ return "#{base}#{path}" if path.start_with?('/')
191
+
192
+ "#{base}/#{path}"
193
+ end
194
+
176
195
  def merge_inherited_options(options)
177
196
  result = options.dup
178
197
  if @inherited_tables.any?
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.3.35'
4
+ VERSION = '0.3.37'
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.3.35
4
+ version: 0.3.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla