Class: RuboCounsel::Counselor

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocounsel/counselor.rb

Overview

The interactive CLI experience for walking through offending cops.

Responsibilities:

- Walk through each offending cop
- Display cop information
- Delegate action prompting to CopPrompt
- Return choices hash for ConfigWriter

Cops that are already configured in .rubocop.yml are skipped by default.

Instance Method Summary collapse

Constructor Details

#initialize(cop_names, catalog: CopCatalog.new, user_config: nil, output: $stdout) ⇒ Counselor

Returns a new instance of Counselor.



17
18
19
20
21
22
# File 'lib/rubocounsel/counselor.rb', line 17

def initialize(cop_names, catalog: CopCatalog.new, user_config: nil, output: $stdout)
  @cop_names = cop_names
  @catalog = catalog
  @user_config_override = user_config
  @output = output
end

Instance Method Details

#counselObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rubocounsel/counselor.rb', line 24

def counsel
  choices = {}

  @cop_names.each do |cop_name|
    choice = counsel_cop(cop_name)
    if choice
      choices[cop_name] = choice
      yield(cop_name, choice) if block_given?
    end
  end

  choices
end