Class: Harbinger::Analyzers::DatabaseDetector
- Inherits:
-
Object
- Object
- Harbinger::Analyzers::DatabaseDetector
- Defined in:
- lib/harbinger/analyzers/database_detector.rb
Overview
Abstract base class for database version detection in Rails projects Provides common functionality for detecting database versions from Rails projects
Direct Known Subclasses
Instance Attribute Summary collapse
-
#project_path ⇒ Object
readonly
Returns the value of attribute project_path.
Instance Method Summary collapse
-
#database_detected? ⇒ Boolean
Check if database.yml indicates this database is used.
-
#detect ⇒ Object
Main detection method - returns version string or nil.
-
#initialize(project_path) ⇒ DatabaseDetector
constructor
A new instance of DatabaseDetector.
Constructor Details
#initialize(project_path) ⇒ DatabaseDetector
Returns a new instance of DatabaseDetector.
13 14 15 |
# File 'lib/harbinger/analyzers/database_detector.rb', line 13 def initialize(project_path) @project_path = project_path end |
Instance Attribute Details
#project_path ⇒ Object (readonly)
Returns the value of attribute project_path.
11 12 13 |
# File 'lib/harbinger/analyzers/database_detector.rb', line 11 def project_path @project_path end |
Instance Method Details
#database_detected? ⇒ Boolean
Check if database.yml indicates this database is used
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/harbinger/analyzers/database_detector.rb', line 34 def database_detected? return false unless database_yml_exists? config = parse_database_yml return false unless config # Check production or default section section = config["production"] || config["default"] || config[config.keys.first] return false unless section adapter = extract_adapter_from_section(section) return false unless adapter Array(adapter_name).any? { |name| adapter == name } end |
#detect ⇒ Object
Main detection method - returns version string or nil
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/harbinger/analyzers/database_detector.rb', line 18 def detect return nil unless database_detected? # Try docker-compose.yml first (most accurate for Docker-based projects) version = detect_from_docker_compose return version if version # Try shell command (actual database version for non-Docker setups) version = detect_from_shell return version if version # Fallback to gem version from Gemfile.lock detect_from_gemfile_lock end |