Module: RailVerdict::RailsContext::Detector

Defined in:
lib/rail_verdict/rails_context/detector.rb

Class Method Summary collapse

Class Method Details

.detect(repository_root:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rail_verdict/rails_context/detector.rb', line 6

def self.detect(repository_root:)
  root = File.realpath(repository_root.to_s) rescue repository_root.to_s
  lockfile = read_text(File.join(root, "Gemfile.lock"), Limits::MAX_FILE_BYTES)
  ruby_version = lockfile ? lockfile[RunContext::GEMFILE_LOCK_RUBY, 1] : nil
  rails_version = lockfile ? lockfile[RunContext::GEMFILE_LOCK_RAILS, 1] : nil
  {
    "ruby_version" => ruby_version,
    "target_ruby_version" => ruby_version,
    "rails_version" => rails_version,
    "test_framework" => detect_test_framework(root, lockfile),
    "database_adapter" => detect_database_adapter(root, lockfile),
    "dependencies" => parse_dependencies(lockfile),
    "structure" => detect_structure(root)
  }
end