Class: FatModelFinder::FileDataPresenter
- Inherits:
-
Object
- Object
- FatModelFinder::FileDataPresenter
- Defined in:
- lib/fat_model_finder/file_data_presenter.rb
Overview
Presentation helper methods to output fat model data rubocop:disable Layout/LineLength
Class Method Summary collapse
-
.colorize_threshold(value, threshold) ⇒ Object
Flag fat model conditions that have passed.
-
.display(file_data:) ⇒ Object
rubocop:disable Metrics/AbcSize.
- .display_tips ⇒ Object
-
.present_fat_model(json_data:) ⇒ Object
rubocop:enable Metrics/AbcSize.
Class Method Details
.colorize_threshold(value, threshold) ⇒ Object
Flag fat model conditions that have passed
55 56 57 |
# File 'lib/fat_model_finder/file_data_presenter.rb', line 55 def self.colorize_threshold(value, threshold) value.to_i > threshold ? value.to_s.colorize(:red) + " - (LIMIT EXCEEDED)".colorize(:red) : value.to_s.colorize(:green) end |
.display(file_data:) ⇒ Object
rubocop:disable Metrics/AbcSize
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fat_model_finder/file_data_presenter.rb', line 8 def self.display(file_data:) puts "File Name: #{file_data.file_name.colorize(:green)}" puts "File Size: #{file_data.file_size} bytes".colorize(:green) puts "File Extension: #{file_data.file_extension.colorize(:green)}" puts "Last Modified: #{file_data.last_modified.to_s.colorize(:green)}" puts "Line Count: #{colorize_threshold(file_data.line_count, FatModelFinder::FileData::LINE_COUNT_THRESHOLD)}" puts "Word Count: #{file_data.word_count.to_s.colorize(:green)}" puts "Character Count: #{file_data.char_count.to_s.colorize(:green)}" puts "Is Empty: #{file_data.is_empty ? "Yes".colorize(:red) : "No".colorize(:green)}" puts "Method Count: #{colorize_threshold(file_data.method_count, FatModelFinder::FileData::METHOD_THRESHOLD)}" puts "Callback Count: #{colorize_threshold(file_data.callback_count, FatModelFinder::FileData::CALLBACK_THRESHOLD)}" puts "Association Count: #{colorize_threshold(file_data.association_count, FatModelFinder::FileData::ASSOCIATION_THRESHOLD)}" puts "Validation Count: #{colorize_threshold(file_data.validation_count, FatModelFinder::FileData::VALIDATION_THRESHOLD)}" puts "\n" end |
.display_tips ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fat_model_finder/file_data_presenter.rb', line 39 def self.display_tips tips = " To address these issues:\n - Reduce the number of methods by moving business logic to service objects or concerns.\n - Minimize callbacks by using them sparingly and considering alternative patterns.\n - Simplify associations by ensuring they are necessary and not overly complex.\n - Break down validations into smaller, reusable components if possible.\n - If the line count is high, split the model into smaller, more focused classes.\n\n Remember, the goal is to keep your models focused and maintainable.\n TIPS\n\n puts tips\nend\n" |
.present_fat_model(json_data:) ⇒ Object
rubocop:enable Metrics/AbcSize
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fat_model_finder/file_data_presenter.rb', line 27 def self.present_fat_model(json_data:) file_name = json_data["file_name"] fat_model_data = json_data["fat_model_data"] || {} = "The model in file '#{file_name.colorize(:red)}' is considered fat due to the following issues:" breakdown = fat_model_data.select { |_key, value| value == true } = breakdown.map { |key, _| "- #{key.to_s.gsub("_", " ").capitalize}".colorize(:red) }.join("\n") puts "#{file_name_message}\n#{breakdown_message}\n\n" end |