Class: RubocopPr::Rubocop
- Inherits:
-
Object
- Object
- RubocopPr::Rubocop
- Includes:
- Enumerable
- Defined in:
- lib/rubocop_pr/rubocop.rb
Overview
small helper for rubocop commands, everything should be stubbed in tests
Constant Summary collapse
- TODO_FILENAME =
'.rubocop_todo.yml'.freeze
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#git ⇒ Object
readonly
Returns the value of attribute git.
Instance Method Summary collapse
- #corrected? ⇒ Boolean
- #each ⇒ Object
- #generate_todo ⇒ Object
-
#initialize(**options) ⇒ Rubocop
constructor
A new instance of Rubocop.
- #read_or_generate_todo ⇒ Object
- #todo ⇒ Object
Constructor Details
#initialize(**options) ⇒ Rubocop
Returns a new instance of Rubocop.
10 11 12 13 |
# File 'lib/rubocop_pr/rubocop.rb', line 10 def initialize(**) @branch = .delete(:branch) @git = .delete(:git) end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
8 9 10 |
# File 'lib/rubocop_pr/rubocop.rb', line 8 def branch @branch end |
#git ⇒ Object (readonly)
Returns the value of attribute git.
8 9 10 |
# File 'lib/rubocop_pr/rubocop.rb', line 8 def git @git end |
Instance Method Details
#corrected? ⇒ Boolean
42 43 44 45 46 |
# File 'lib/rubocop_pr/rubocop.rb', line 42 def corrected? `bundle exec rubocop -a` git.checkout TODO_FILENAME !git.status.blank? end |
#each ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubocop_pr/rubocop.rb', line 19 def each git.checkout(branch) todos_backup = todo todos_backup.keys.sort.reverse_each do |cop| git.checkout(branch) todos = todos_backup.dup todos.delete cop File.open(TODO_FILENAME, 'w') { |f| f.write todos.blank? ? '' : YAML.dump(todos) } yield cop end end |
#generate_todo ⇒ Object
38 39 40 |
# File 'lib/rubocop_pr/rubocop.rb', line 38 def generate_todo `bundle exec rubocop --auto-gen-config` end |
#read_or_generate_todo ⇒ Object
31 32 33 34 35 36 |
# File 'lib/rubocop_pr/rubocop.rb', line 31 def read_or_generate_todo return File.read(TODO_FILENAME) if File.exist?(TODO_FILENAME) generate_todo git.commit_all('Generate initial Rubocop todo file') File.read(TODO_FILENAME) end |
#todo ⇒ Object
15 16 17 |
# File 'lib/rubocop_pr/rubocop.rb', line 15 def todo YAML.safe_load(read_or_generate_todo) end |