Module: Belt::CLI::AppDetection
- Included in:
- DestroyCommand, EnvironmentCommand, FrontendCommand, FrontendDeployCommand, FrontendEnvCommand, FrontendSetupCommand, GenerateCommand, LambdaConfigCommand, LogsCommand, ServerCommand, SetupCommand
- Defined in:
- lib/belt/cli/app_detection.rb
Instance Method Summary collapse
-
#detect_app_name ⇒ Object
Detects the application name.
-
#detect_environments ⇒ Object
Detects existing environments by scanning infrastructure/ directories.
-
#detect_namespace ⇒ Object
Detects the primary namespace from the route definitions.
-
#find_contracts_file_path ⇒ Object
Finds contracts file checking config/contracts.rb first, then legacy paths.
-
#find_routes_file_path ⇒ Object
Finds routes file checking config/routes.rb first, then legacy paths.
-
#find_schema_file_path ⇒ Object
Legacy alias for backward compatibility.
-
#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_environments ⇒ Object
Detects existing environments by scanning infrastructure/ directories. Each subdirectory with a main.tf is considered an environment.
33 34 35 |
# File 'lib/belt/cli/app_detection.rb', line 33 def detect_environments Dir.glob('infrastructure/*/main.tf').map { |f| File.basename(File.dirname(f)) }.sort 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 = find_routes_file_path if routes_file && File.exist?(routes_file) match = File.read(routes_file).match(/namespace :(\w+)/) return match[1] if match end File.basename(Dir.pwd) end |
#find_contracts_file_path ⇒ Object
Finds contracts file checking config/contracts.rb first, then legacy paths.
54 55 56 57 58 59 60 61 62 |
# File 'lib/belt/cli/app_detection.rb', line 54 def find_contracts_file_path candidates = [ 'config/contracts.rb', 'config/contracts.tf.rb', 'config/schema.tf.rb', 'infrastructure/schema.tf.rb' ] candidates.find { |f| File.exist?(f) } end |
#find_routes_file_path ⇒ Object
Finds routes file checking config/routes.rb first, then legacy paths.
44 45 46 47 48 49 50 51 |
# File 'lib/belt/cli/app_detection.rb', line 44 def find_routes_file_path candidates = [ 'config/routes.rb', 'config/routes.tf.rb', 'infrastructure/routes.tf.rb' ] candidates.find { |f| File.exist?(f) } end |
#find_schema_file_path ⇒ Object
Legacy alias for backward compatibility
65 66 67 |
# File 'lib/belt/cli/app_detection.rb', line 65 def find_schema_file_path find_contracts_file_path 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.
39 40 41 |
# File 'lib/belt/cli/app_detection.rb', line 39 def s3_safe_name(name) name.to_s.downcase.tr('_', '-') end |