Class: Reek::CLI::Command::TodoListCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Reek::CLI::Command::TodoListCommand
- Defined in:
- lib/reek/cli/command/todo_list_command.rb
Overview
A command to collect smells from a set of sources and writes a configuration file that can serve as a todo list.
Constant Summary collapse
- HEADER =
"# Auto generated by Reeks --todo flag\n"
- EXISTING_FILE_MESSAGE =
"\nExisting '#{DEFAULT_CONFIGURATION_FILE_NAME}' detected - aborting.\n".freeze
- NO_SMELLS_FOUND_MESSAGE =
"\nNo smells found - nothing to do, exiting.\n"
Instance Attribute Summary
Attributes inherited from BaseCommand
#configuration, #options, #sources
Instance Method Summary collapse
- #execute ⇒ Object
- #grouped_smells ⇒ Object private
- #groups ⇒ Object private
- #smells ⇒ Object private
-
#write_to_file ⇒ Object
private
:reek:FeatureEnvy.
Methods inherited from BaseCommand
Constructor Details
This class inherits a constructor from Reek::CLI::Command::BaseCommand
Instance Method Details
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/reek/cli/command/todo_list_command.rb', line 19 def execute if smells.empty? puts NO_SMELLS_FOUND_MESSAGE elsif File.exist?(DEFAULT_CONFIGURATION_FILE_NAME) puts EXISTING_FILE_MESSAGE else write_to_file puts "\n'#{DEFAULT_CONFIGURATION_FILE_NAME}' generated! " \ 'You can now use this as a starting point.' end .success_exit_code end |
#grouped_smells ⇒ Object (private)
51 52 53 |
# File 'lib/reek/cli/command/todo_list_command.rb', line 51 def grouped_smells @grouped_smells ||= smells.group_by(&:smell_type) end |
#groups ⇒ Object (private)
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/reek/cli/command/todo_list_command.rb', line 40 def groups @groups ||= begin todos = DetectorRepository.smell_types.map do |smell_class| smells_for_class = grouped_smells[smell_class.smell_type] or next smell_class.todo_configuration_for(smells_for_class) end todos.compact.inject(&:merge) end end |
#smells ⇒ Object (private)
34 35 36 37 38 |
# File 'lib/reek/cli/command/todo_list_command.rb', line 34 def smells @smells ||= sources.map do |source| Examiner.new(source, filter_by_smells: smell_names) end.map(&:smells).flatten end |
#write_to_file ⇒ Object (private)
:reek:FeatureEnvy
56 57 58 59 60 61 |
# File 'lib/reek/cli/command/todo_list_command.rb', line 56 def write_to_file File.open(DEFAULT_CONFIGURATION_FILE_NAME, 'w') do |configuration_file| configuration_file.write HEADER configuration_file.write({ DETECTORS_KEY => groups }.to_yaml) end end |