Class: Harbinger::Analyzers::DatabaseDetector

Inherits:
Object
  • Object
show all
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

MysqlDetector, PostgresDetector

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathObject (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

Returns:

  • (Boolean)


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

#detectObject

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