Class: RailsDoctor::Init::Runner

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

Constant Summary collapse

{
  "rubocop" => "development,test",
  "rubocop-rails" => "development,test",
  "brakeman" => "development,test",
  "bundler-audit" => "development,test",
  "reek" => "development,test",
  "strong_migrations" => "development,test",
  "prosopite" => "development,test",
  "simplecov" => "development,test",
  "flog" => "development,test",
  "flay" => "development,test"
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project:, config:, runner:, options:) ⇒ Runner

Returns a new instance of Runner.



24
25
26
27
28
29
# File 'lib/rails_doctor/init/runner.rb', line 24

def initialize(project:, config:, runner:, options:)
  @project = project
  @config = config
  @runner = runner
  @options = options
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/rails_doctor/init/runner.rb', line 22

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/rails_doctor/init/runner.rb', line 22

def options
  @options
end

#projectObject (readonly)

Returns the value of attribute project.



22
23
24
# File 'lib/rails_doctor/init/runner.rb', line 22

def project
  @project
end

#runnerObject (readonly)

Returns the value of attribute runner.



22
23
24
# File 'lib/rails_doctor/init/runner.rb', line 22

def runner
  @runner
end

Instance Method Details

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rails_doctor/init/runner.rb', line 31

def run
  changes = planned_changes
  lines = []
  lines << "Rails Doctor init"
  lines << "Profile: #{options.fetch(:profile, "recommended")}"
  lines << ""
  lines << "Planned file changes"
  changes.each do |change|
    lines << "- #{change.fetch(:path)} (#{change.fetch(:action)})"
  end
  lines << ""

  missing = missing_gems
  if missing.any?
    lines << "Missing recommended gems"
    missing.each { |gem| lines << "- #{gem} (#{RECOMMENDED_GEMS.fetch(gem)})" }
    lines << ""
  end

  if options[:dry_run]
    lines << "Dry run only. No files were changed."
    return lines.join("\n") + "\n"
  end

  if options[:yes] || confirm?("Apply Rails Doctor configuration? [y/N] ")
    changes.each { |change| write_change(change) }
    lines << "Wrote Rails Doctor configuration."
  else
    lines << "Skipped file changes."
  end

  if missing.any? && should_install_missing?
    install_missing(missing, lines)
  elsif missing.any?
    lines << "Skipped gem installation. Run rails-doctor init --install to install missing tools."
  end

  lines.join("\n") + "\n"
end