Class: BestPracticeProject::RubocopHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- BestPracticeProject::RubocopHandler
- Defined in:
- lib/best_practice_project/rubocop_handler.rb
Instance Method Summary collapse
- #command ⇒ Object
- #execute ⇒ Object
- #generate_config ⇒ Object
- #generate_todo_config ⇒ Object
-
#initialize(args) ⇒ RubocopHandler
constructor
A new instance of RubocopHandler.
- #installed? ⇒ Boolean
Methods inherited from BaseHandler
Constructor Details
#initialize(args) ⇒ RubocopHandler
Returns a new instance of RubocopHandler.
2 3 4 5 6 7 8 9 10 11 12 13 14 |
# 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 |
Instance Method Details
#command ⇒ Object
16 17 18 19 20 21 |
# 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 ⇒ Object
39 40 41 |
# File 'lib/best_practice_project/rubocop_handler.rb', line 39 def execute system(command) end |
#generate_config ⇒ Object
23 24 25 26 27 28 29 30 |
# 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 ⇒ Object
32 33 34 35 36 37 |
# 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? ⇒ Boolean
43 44 45 46 47 48 |
# File 'lib/best_practice_project/rubocop_handler.rb', line 43 def installed? require "rubocop" true rescue LoadError false end |