Class: RailsDoctor::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_doctor/config.rb

Constant Summary collapse

DEFAULT_FILE =
".rails-doctor.yml"
DEFAULTS =
{
  "version" => 1,
  "profiles" => {
    "fast" => {
      "adapters" => %w[rubocop brakeman zeitwerk rails_checks],
      "run_tests" => false,
      "network" => false,
      "deep_quality" => false
    },
    "recommended" => {
      "adapters" => %w[rubocop brakeman bundler_audit zeitwerk reek strong_migrations rails_checks],
      "run_tests" => false,
      "network" => false,
      "deep_quality" => false
    },
    "ci" => {
      "adapters" => %w[rubocop brakeman bundler_audit zeitwerk reek strong_migrations rails_checks test_runner test_coverage],
      "run_tests" => true,
      "network" => false,
      "deep_quality" => false
    },
    "deep" => {
      "adapters" => %w[rubocop brakeman bundler_audit zeitwerk reek strong_migrations rails_checks test_runner test_coverage flog flay dependency_freshness],
      "run_tests" => true,
      "network" => true,
      "deep_quality" => true
    }
  },
  "commands" => {
    "rubocop" => "bundle exec rubocop --format json",
    "brakeman" => "bundle exec brakeman --format json --quiet",
    "bundler_audit" => "bundle exec bundle-audit check --format json",
    "zeitwerk" => "bundle exec rails zeitwerk:check",
    "reek" => "bundle exec reek --format json",
    "flog" => "bundle exec flog app lib",
    "flay" => "bundle exec flay app lib",
    "dependency_freshness" => "bundle outdated --parseable",
    "test" => nil
  },
  "reports" => {
    "default_format" => "terminal",
    "output_dir" => "tmp/rails-doctor",
    "include_raw_output" => true
  },
  "coverage" => {
    "enabled" => true,
    "source" => "simplecov",
    "result_path" => "coverage/.resultset.json",
    "include" => [
      "app/**/*.rb",
      "lib/**/*.rb"
    ],
    "max_files" => 10
  },
  "thresholds" => {
    "fail_on" => nil,
    "min_score" => nil,
    "coverage" => {
      "line" => 90.0,
      "file_line" => 80.0,
      "branch" => nil
    },
    "large_file_lines" => {
      "model" => 250,
      "controller" => 220,
      "job" => 160,
      "mailer" => 160,
      "view" => 180
    },
    "todo_density_per_100_lines" => 2.0,
    "flog_high_score" => 25.0
  },
  "git" => {
    "churn_window_days" => 90,
    "base_ref" => nil
  },
  "agents" => {
    "codex" => {
      "command" => "codex exec",
      "apply_requires_clean_worktree" => true
    },
    "claude-code" => {
      "command" => "claude",
      "apply_requires_clean_worktree" => true
    },
    "cursor" => {
      "command" => "cursor-agent",
      "apply_requires_clean_worktree" => true
    }
  }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_root:, path: nil, data: nil) ⇒ Config

Returns a new instance of Config.



103
104
105
106
107
# File 'lib/rails_doctor/config.rb', line 103

def initialize(project_root:, path: nil, data: nil)
  @project_root = File.expand_path(project_root)
  @path = path || File.join(@project_root, DEFAULT_FILE)
  @data = deep_merge(DEFAULTS, data || load_file(@path))
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



101
102
103
# File 'lib/rails_doctor/config.rb', line 101

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



101
102
103
# File 'lib/rails_doctor/config.rb', line 101

def path
  @path
end

#project_rootObject (readonly)

Returns the value of attribute project_root.



101
102
103
# File 'lib/rails_doctor/config.rb', line 101

def project_root
  @project_root
end

Class Method Details

.load(project_root:, path: nil) ⇒ Object



109
110
111
# File 'lib/rails_doctor/config.rb', line 109

def self.load(project_root:, path: nil)
  new(project_root: project_root, path: path)
end

Instance Method Details

#adapters_for(profile_name) ⇒ Object



119
120
121
# File 'lib/rails_doctor/config.rb', line 119

def adapters_for(profile_name)
  profile(profile_name).fetch("adapters")
end

#agent(name) ⇒ Object



131
132
133
# File 'lib/rails_doctor/config.rb', line 131

def agent(name)
  data.fetch("agents", {})[name.to_s]
end

#command(name) ⇒ Object



123
124
125
# File 'lib/rails_doctor/config.rb', line 123

def command(name)
  data.fetch("commands", {})[name.to_s]
end

#profile(name) ⇒ Object



113
114
115
116
117
# File 'lib/rails_doctor/config.rb', line 113

def profile(name)
  data.fetch("profiles").fetch(name) do
    raise Error, "Unknown profile #{name.inspect}. Available profiles: #{data.fetch("profiles").keys.join(", ")}"
  end
end

#report_output_dirObject



135
136
137
# File 'lib/rails_doctor/config.rb', line 135

def report_output_dir
  File.join(project_root, data.fetch("reports").fetch("output_dir"))
end

#threshold(key) ⇒ Object



127
128
129
# File 'lib/rails_doctor/config.rb', line 127

def threshold(key)
  data.fetch("thresholds", {})[key.to_s]
end

#to_yamlObject



139
140
141
# File 'lib/rails_doctor/config.rb', line 139

def to_yaml
  data.to_yaml
end