Module: Belt::CLI::AppDetection

Instance Method Summary collapse

Instance Method Details

#detect_app_nameObject

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_environmentsObject

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_namespaceObject

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.



39
40
41
# File 'lib/belt/cli/app_detection.rb', line 39

def s3_safe_name(name)
  name.to_s.downcase.tr('_', '-')
end