Class: Rubomop::Runner
- Inherits:
-
Object
- Object
- Rubomop::Runner
- Defined in:
- lib/rubomop/runner.rb
Constant Summary collapse
- NUM_STRING =
"Number of cleanups to perform (default: 10)"- AUTOCORRECT_STRING =
"Only clean autocorrectable cops (default)"- NO_AUTOCORRECT_STRING =
"Clean all cops (not default)"- RUBOCOP_STRING =
"Run rubocop -aD after (default)"- NO_RUBOCOP_STRING =
"Don't run rubocop -aD after (not default)"- FILENAME_STRING =
"Name of todo file (default: ./.rubocop_todo.yml)"- CONFIG_STRING =
"Name of optional config file (default: .rubomop.yml)"- ONLY_STRING =
"String or regex of cops to limit removal do, can have multiple"- EXCEPT_STRING =
"String or regex of cops to not remove from, can have multiple"- BLOCK_STRING =
"String or regex of files to not touch, can have multiple"
Instance Attribute Summary collapse
-
#autocorrect_only ⇒ Object
Returns the value of attribute autocorrect_only.
-
#block ⇒ Object
Returns the value of attribute block.
-
#config ⇒ Object
Returns the value of attribute config.
-
#except ⇒ Object
Returns the value of attribute except.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#number ⇒ Object
Returns the value of attribute number.
-
#only ⇒ Object
Returns the value of attribute only.
-
#options_from_command_line ⇒ Object
Returns the value of attribute options_from_command_line.
-
#run_rubocop ⇒ Object
Returns the value of attribute run_rubocop.
-
#todo ⇒ Object
Returns the value of attribute todo.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #backup_existing_file ⇒ Object
- #execute(args) ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #load_from_file ⇒ Object
- #load_options(args) ⇒ Object
- #mop ⇒ Object
- #parse(args) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rubomop/runner.rb', line 18 def initialize @number = 10 @autocorrect_only = true @run_rubocop = true @filename = ".rubocop_todo.yml" @config = ".rubomop.yml" @todo = nil @verbose = true @options_from_command_line = [] @only = [] @except = [] @block = [] end |
Instance Attribute Details
#autocorrect_only ⇒ Object
Returns the value of attribute autocorrect_only.
3 4 5 |
# File 'lib/rubomop/runner.rb', line 3 def autocorrect_only @autocorrect_only end |
#block ⇒ Object
Returns the value of attribute block.
5 6 7 |
# File 'lib/rubomop/runner.rb', line 5 def block @block end |
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/rubomop/runner.rb', line 4 def config @config end |
#except ⇒ Object
Returns the value of attribute except.
5 6 7 |
# File 'lib/rubomop/runner.rb', line 5 def except @except end |
#filename ⇒ Object
Returns the value of attribute filename.
4 5 6 |
# File 'lib/rubomop/runner.rb', line 4 def filename @filename end |
#number ⇒ Object
Returns the value of attribute number.
3 4 5 |
# File 'lib/rubomop/runner.rb', line 3 def number @number end |
#only ⇒ Object
Returns the value of attribute only.
5 6 7 |
# File 'lib/rubomop/runner.rb', line 5 def only @only end |
#options_from_command_line ⇒ Object
Returns the value of attribute options_from_command_line.
4 5 6 |
# File 'lib/rubomop/runner.rb', line 4 def @options_from_command_line end |
#run_rubocop ⇒ Object
Returns the value of attribute run_rubocop.
3 4 5 |
# File 'lib/rubomop/runner.rb', line 3 def run_rubocop @run_rubocop end |
#todo ⇒ Object
Returns the value of attribute todo.
4 5 6 |
# File 'lib/rubomop/runner.rb', line 4 def todo @todo end |
#verbose ⇒ Object
Returns the value of attribute verbose.
4 5 6 |
# File 'lib/rubomop/runner.rb', line 4 def verbose @verbose end |
Instance Method Details
#backup_existing_file ⇒ Object
116 117 118 119 |
# File 'lib/rubomop/runner.rb', line 116 def backup_existing_file FileUtils.rm("#{filename}.bak") if File.exist?("#{filename}.bak") FileUtils.mv(filename, "#{filename}.bak") end |
#execute(args) ⇒ Object
32 33 34 35 |
# File 'lib/rubomop/runner.rb', line 32 def execute(args) (args) run end |
#load_from_file ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rubomop/runner.rb', line 42 def load_from_file return unless File.exist?(config) = YAML.safe_load(File.read(config)) .each do |key, value| next if .include?(key) send("#{key.underscore}=", value) if respond_to?("#{key.underscore}=") end rescue Psych::Exception nil end |
#load_options(args) ⇒ Object
37 38 39 40 |
# File 'lib/rubomop/runner.rb', line 37 def (args) parse(args) load_from_file end |
#mop ⇒ Object
104 105 106 |
# File 'lib/rubomop/runner.rb', line 104 def mop Mop.new(todo, number, autocorrect_only, verbose, run_rubocop, only, except, block) end |
#parse(args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rubomop/runner.rb', line 53 def parse(args) option_parser = OptionParser.new do |opts| opts. = "Usage: rubomop [options]" opts.on("-nNUMBER", "--number NUMBER", Integer, NUM_STRING) do |value| self.number = value @options_from_command_line << "number" end opts.on("-a", "--autocorrect-only", AUTOCORRECT_STRING) do self.autocorrect_only = true @options_from_command_line << "autocorrect-only" end opts.on("--no_autocorrect-only", NO_AUTOCORRECT_STRING) do self.autocorrect_only = false @options_from_command_line << "autocorrect-only" end opts.on("-r", "--run-rubocop", RUBOCOP_STRING) do self.run_rubocop = true @options_from_command_line << "run-rubocop" end opts.on("-fFILENAME", "--filename=FILENAME", FILENAME_STRING) do |value| self.filename = value @options_from_command_line << "filename" end opts.on("--no-run-rubocop", NO_RUBOCOP_STRING) do self.run_rubocop = false @options_from_command_line << "run-rubocop" end opts.on("-cCONFIG_FILE", "--config=CONFIG_FILE", CONFIG_STRING) do |value| self.config = value @options_from_command_line << "config" end opts.on("--only=ONLY", ONLY_STRING) do |value| only << value @options_from_command_line << "only" end opts.on("--except=EXCEPT", ONLY_STRING) do |value| except << value @options_from_command_line << "except" end opts.on("--block=BLOCK", BLOCK_STRING) do |value| block << value @options_from_command_line << "block" end opts.on("-h", "--help", "Prints this help") do puts opts exit end end option_parser.parse(args) end |