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.
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ 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.
20 21 22 23 |
# File 'lib/rubocop_pr/rubocop.rb', line 20 def initialize(**) @branch = .delete(:branch) @git = .delete(:git) end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
18 19 20 |
# File 'lib/rubocop_pr/rubocop.rb', line 18 def branch @branch end |
#git ⇒ Object (readonly)
Returns the value of attribute git.
18 19 20 |
# File 'lib/rubocop_pr/rubocop.rb', line 18 def git @git end |
Class Method Details
.correct!(all) ⇒ Object
13 14 15 |
# File 'lib/rubocop_pr/rubocop.rb', line 13 def correct!(all) system "bundle exec rubocop -#{all ? 'A' : 'a'}" end |
.generate_todo ⇒ Object
9 10 11 |
# File 'lib/rubocop_pr/rubocop.rb', line 9 def generate_todo system 'bundle exec rubocop --auto-gen-config' end |
Instance Method Details
#each ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/rubocop_pr/rubocop.rb', line 29 def each todo.keys.sort.reverse_each do |cop| git.checkout(branch) File.open(TODO_FILENAME, 'w') do |f| f.write todo.except(cop.to_s).blank? ? '' : YAML.dump(todo.except(cop.to_s)) end yield Cop.new(name: cop) end end |
#read_or_generate_todo ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/rubocop_pr/rubocop.rb', line 39 def read_or_generate_todo git.checkout(branch) return File.read(TODO_FILENAME) if File.exist?(TODO_FILENAME) self.class.generate_todo git.commit_all('Generate initial Rubocop todo file') File.read(TODO_FILENAME) end |
#todo ⇒ Object
25 26 27 |
# File 'lib/rubocop_pr/rubocop.rb', line 25 def todo @todo ||= YAML.safe_load(read_or_generate_todo) end |