class BestPracticeProject::RubocopHandler

Public Class Methods

new(args) click to toggle source
Calls superclass method BestPracticeProject::BaseHandler::new
# File lib/best_practice_project/rubocop_handler.rb, line 2
def initialize(args)
  super

  @actual_config_path = File.realpath("#{File.dirname(__FILE__)}/config/rubocop.yml")

  if rails?
    @config_path = Rails.root.join(".rubocop.yml").to_s
    @todo_path = Rails.root.join(".rubocop_todo.yml").to_s
  else
    @config_path = ".rubocop.yml"
    @todo_path = ".rubocop_todo.yml"
  end
end

Public Instance Methods

command() click to toggle source
# File lib/best_practice_project/rubocop_handler.rb, line 16
def command
  command = "bundle exec rubocop --display-cop-names --enable-pending-cops"
  command << " --auto-correct" if ARGV.include?("auto-correct")

  command
end
execute() click to toggle source
# File lib/best_practice_project/rubocop_handler.rb, line 39
def execute
  system(command)
end
generate_config() click to toggle source
# File lib/best_practice_project/rubocop_handler.rb, line 23
def generate_config
  FileUtils.copy(@actual_config_path, @config_path)

  generate_todo_config

  puts "Generated Rubocop todo config in #{@todo_path}"
  puts "Generated Rubocop config in  #{@config_path}"
end
generate_todo_config() click to toggle source
# File lib/best_practice_project/rubocop_handler.rb, line 32
def generate_todo_config
  rubocop_command = "rubocop --display-cop-names --enable-pending-cops --auto-gen-config --config=#{@config_path}"
  rubocop_command << " --rails" if rails?

  system(rubocop_command)
end
installed?() click to toggle source
# File lib/best_practice_project/rubocop_handler.rb, line 43
def installed?
  require "rubocop"
  true
rescue LoadError
  false
end