Module: Belt::CLI::AppDetection
- Included in:
- EnvironmentCommand, FrontendCommand, FrontendDeployCommand, FrontendSetupCommand, GenerateCommand, ServerCommand, SetupCommand, TablesCommand
- Defined in:
- lib/belt/cli/app_detection.rb
Instance Method Summary collapse
-
#detect_app_name ⇒ Object
Detects the application name.
-
#detect_namespace ⇒ Object
Detects the primary namespace from the route definitions.
-
#s3_safe_name(name) ⇒ Object
S3 bucket names follow DNS rules — underscores are not allowed.
Instance Method Details
#detect_app_name ⇒ Object
Detects the application name. Prefers terraform.tfvars app_name, then falls back to directory name.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/belt/cli/app_detection.rb', line 19 def detect_app_name # Check any environment tfvars for the app_name Dir.glob('infrastructure/*/terraform.tfvars').each do |f| content = File.read(f) match = content.match(/app_name\s*=\s*"([^"]+)"/) return match[1] if match end # Fall back to directory name File.basename(Dir.pwd) end |
#detect_namespace ⇒ Object
Detects the primary namespace from the route definitions. Used by generators to determine controller directory and route file naming.
8 9 10 11 12 13 14 15 |
# File 'lib/belt/cli/app_detection.rb', line 8 def detect_namespace routes_file = 'infrastructure/routes.tf.rb' if File.exist?(routes_file) match = File.read(routes_file).match(/namespace :(\w+)/) return match[1] if match end File.basename(Dir.pwd) end |
#s3_safe_name(name) ⇒ Object
S3 bucket names follow DNS rules — underscores are not allowed. App names often use underscores (Ruby namespaces); convert for S3.
33 34 35 |
# File 'lib/belt/cli/app_detection.rb', line 33 def s3_safe_name(name) name.to_s.downcase.tr('_', '-') end |