Class: AttributeStats::TabularFormatter
- Inherits:
-
Object
- Object
- AttributeStats::TabularFormatter
- Defined in:
- lib/formatters/tabular_formatter.rb
Instance Method Summary collapse
-
#initialize(options: {}, table_info: {}, migration: nil) ⇒ TabularFormatter
constructor
A new instance of TabularFormatter.
- #output_all_attributes ⇒ Object
- #output_attribute_references ⇒ Object
- #output_dormant_tables ⇒ Object
- #output_unused_attributes ⇒ Object
Constructor Details
#initialize(options: {}, table_info: {}, migration: nil) ⇒ TabularFormatter
Returns a new instance of TabularFormatter.
6 7 8 9 |
# File 'lib/formatters/tabular_formatter.rb', line 6 def initialize(options: {}, table_info: {}, migration: nil) , @table_info, @migration = , table_info, migration @buffer = '' end |
Instance Method Details
#output_all_attributes ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/formatters/tabular_formatter.rb', line 11 def output_all_attributes attribute_results = [] @table_info.each do |table_info| table_info.attributes.sort_by(&:usage_percent).each do |attribute| attribute_results << { model: table_info.name, set_count: attribute.count, set_percent: (attribute.usage_percent * 100).round(1).to_s.rjust(5), attribute_name: attribute.name } end end if attribute_results.empty? puts "No attributes found" else print_table attribute_results, title: 'Attributes Utilization' end @buffer end |
#output_attribute_references ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/formatters/tabular_formatter.rb', line 31 def output_attribute_references output = [] @table_info.each do |table_info| table_info.attributes.each do |attribute| next unless attribute.empty? output << { model: table_info.name, attribute_name: attribute.name, all_references: attribute.total_references, code: attribute.references['app'], specs: attribute.references['spec'], views: attribute.references['views'] } end end output.sort!{|a,b| a[:all_references] <=> b[:all_references]} if output.empty? puts "No unused attributes found" else print_table output, title: ['Attribute Code References', 'Mentions of the attribute name in app/ (except assets), lib/, config/, and spec/', '(symbol or dot notation, or wrapped in quotes)'] end @buffer end |
#output_dormant_tables ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/formatters/tabular_formatter.rb', line 55 def output_dormant_tables output = [] @table_info.each do |table_info| date = table_info.last_updated output << { model: table_info.name, last_updated: date.nil? ? 'Never Updated' : table_info.last_updated.to_date.to_s(:long) } if table_info.dormant? end if output.empty? puts "No dormant tables" else print_table output, title: ['Dormant Tables', "No updated_ats after #{@options[:dormant_table_age].to_date.to_s(:long)}"] end @buffer end |
#output_unused_attributes ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/formatters/tabular_formatter.rb', line 72 def output_unused_attributes output = [] @table_info.each do |table_info| table_info.attributes.sort_by(&:name).each do |attribute| output << { model: table_info.name, attribute_name: attribute.name } if attribute.empty? end end unused_values = ['Nil', 'Empty'] unused_values << 'Default Values' if [:consider_defaults_unused] if output.empty? puts "No unused attributes (good for you!)" else print_table output, title: ['Unused Attributes', unused_values.join(', ')] end @buffer end |