Module: BeltHelpers
- Included in:
- BeltEnvironment
- Defined in:
- lib/brainiac/handlers/shared/belt.rb
Overview
Module containing Belt-related helpers accessible from Sinatra routes.
Instance Method Summary collapse
-
#belt_app?(path) ⇒ Boolean
Detect if a directory is a Belt application by checking for routes file.
-
#belt_routes_file?(path) ⇒ Boolean
Check if a Belt app routes file exists and contains actual route definitions.
-
#belt_routes_path(path) ⇒ String?
Get the path to the Belt routes file (checking all possible locations).
Instance Method Details
#belt_app?(path) ⇒ Boolean
Detect if a directory is a Belt application by checking for routes file.
Belt apps are detected by the presence of any of these files:
- config/routes.rb (current)
- config/routes.tf.rb (legacy)
- infrastructure/routes.tf.rb (legacy)
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 23 def belt_app?(path) return false unless path && File.directory?(path) candidates = [ File.join(path, "config/routes.rb"), File.join(path, "config/routes.tf.rb"), File.join(path, "infrastructure/routes.tf.rb") ] candidates.any? { |f| File.exist?(f) } end |
#belt_routes_file?(path) ⇒ Boolean
Check if a Belt app routes file exists and contains actual route definitions. This is a stricter check than belt_app? — it verifies the file has Belt routes, not just a Rails routes.rb file (which wouldn't have Belt-style route definitions).
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 40 def belt_routes_file?(path) routes_file = belt_routes_path(path) return false unless routes_file && File.exist?(routes_file) # Check for Belt-specific syntax (e.g., `app.get`, `api`, `resources`, etc.) content = File.read(routes_file, 4096) # Read first 4KB content.match?(/\bapp\.(get|post|put|patch|delete)\b/) || content.match?(/\bapi\s+do\b/) || content.match?(/\bresources?\s+:/) || content.match?(/\bBelt\.routes\b/) rescue StandardError false end |
#belt_routes_path(path) ⇒ String?
Get the path to the Belt routes file (checking all possible locations).
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 58 def belt_routes_path(path) return nil unless path && File.directory?(path) candidates = [ File.join(path, "config/routes.rb"), File.join(path, "config/routes.tf.rb"), File.join(path, "infrastructure/routes.tf.rb") ] candidates.find { |f| File.exist?(f) } end |