Class: Docscribe::CLI::Formatters::Text
- Inherits:
-
Object
- Object
- Docscribe::CLI::Formatters::Text
- Defined in:
- lib/docscribe/cli/formatters/text.rb
Overview
Text output formatter preserving the original CLI output format.
Instance Method Summary collapse
-
#format_check_status_line(state) ⇒ void
Print check status line.
-
#format_check_summary(state:, options:) ⇒ void
Format and print check summary.
-
#format_corrected_paths(state, options) ⇒ void
Print updated file paths.
-
#format_error_paths(state) ⇒ void
Print error file messages.
-
#format_fail_paths(state, options) ⇒ void
Print files needing updates.
-
#format_type_mismatch_paths(state, options) ⇒ void
Print type mismatch warnings.
-
#format_write_summary(state:, options:) ⇒ void
Format and print write summary.
Instance Method Details
#format_check_status_line(state) ⇒ void
This method returns an undefined value.
Print check status line.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/docscribe/cli/formatters/text.rb', line 58 def format_check_status_line(state) checked_error = state[:error_paths].size type_mismatch_count = state[:type_mismatch_paths].size if all_fine?(state, checked_error, type_mismatch_count) puts "Docscribe: OK (#{state[:checked_ok]} files checked)" elsif mismatch_only?(state, checked_error) puts "Docscribe: OK (#{state[:checked_ok]} files checked, #{type_mismatch_count} with type mismatches)" else puts failure_line(state, type_mismatch_count, checked_error) end end |
#format_check_summary(state:, options:) ⇒ void
This method returns an undefined value.
Format and print check summary.
13 14 15 16 17 18 19 |
# File 'lib/docscribe/cli/formatters/text.rb', line 13 def format_check_summary(state:, options:) puts format_fail_paths(state, ) format_check_status_line(state) format_type_mismatch_paths(state, ) format_error_paths(state) end |
#format_corrected_paths(state, options) ⇒ void
This method returns an undefined value.
Print updated file paths.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/docscribe/cli/formatters/text.rb', line 93 def format_corrected_paths(state, ) state[:corrected_paths].each do |p| puts "Updated: #{p}" next if [:verbose] || [:quiet] Array(state[:corrected_changes][p]).each do |change| puts " - #{format_change_reason(change)}" end end end |
#format_error_paths(state) ⇒ void
This method returns an undefined value.
Print error file messages.
109 110 111 112 113 114 115 116 117 |
# File 'lib/docscribe/cli/formatters/text.rb', line 109 def format_error_paths(state) return if state[:error_paths].empty? warn '' state[:error_paths].each do |p| warn "Error processing: #{p}" warn " #{state[:error_messages][p]}" if state[:error_messages][p] end end |
#format_fail_paths(state, options) ⇒ void
This method returns an undefined value.
Print files needing updates.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/docscribe/cli/formatters/text.rb', line 42 def format_fail_paths(state, ) state[:fail_paths].each do |p| puts "Would update: #{p}" next if [:verbose] || [:quiet] Array(state[:fail_changes][p]).each do |change| puts " - #{format_change_reason(change)}" end end end |
#format_type_mismatch_paths(state, options) ⇒ void
This method returns an undefined value.
Print type mismatch warnings.
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/docscribe/cli/formatters/text.rb', line 76 def format_type_mismatch_paths(state, ) return if [:quiet] return unless [:verbose] || [:explain] state[:type_mismatch_paths].each do |p| warn "Type mismatches: #{p}" Array(state[:type_mismatch_changes][p]).each do |change| warn " - #{format_change_reason(change)}" end end end |
#format_write_summary(state:, options:) ⇒ void
This method returns an undefined value.
Format and print write summary.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/docscribe/cli/formatters/text.rb', line 26 def format_write_summary(state:, options:) puts puts "Docscribe: updated #{state[:corrected]} file(s)" if state[:corrected].positive? format_corrected_paths(state, ) return unless state[:had_errors] warn "Docscribe: #{state[:error_paths].size} file(s) had errors" format_error_paths(state) end |