class AttributeStats::HashFormatter
Public Class Methods
new(options: {}, table_info: {}, migration: [])
click to toggle source
# File lib/formatters/hash_formatter.rb, line 4 def initialize(options: {}, table_info: {}, migration: []) @options, @table_info, @migration = options, table_info, migration end
Public Instance Methods
output_all_attributes()
click to toggle source
# File lib/formatters/hash_formatter.rb, line 26 def output_all_attributes output = [] @table_info.each do |table_info| table_info.attributes.each do |attribute| output << { model: table_info.name, attribute: attribute.name, count: attribute.count, usage_percent: attribute.usage_percent } end end output end
output_attribute_references()
click to toggle source
# File lib/formatters/hash_formatter.rb, line 8 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: attribute.name, all_references: attribute.total_references, code_references: attribute.references['app'], spec_references: attribute.references['spec'], view_references: attribute.references['views'] } end end output.sort!{|a,b| a[:all_references] <=> b[:all_references]} end
output_dormant_tables()
click to toggle source
# File lib/formatters/hash_formatter.rb, line 41 def output_dormant_tables output = [] @table_info.each do |table_info| output << table_info.table_name if table_info.dormant? end output end
output_unused_attributes()
click to toggle source
# File lib/formatters/hash_formatter.rb, line 49 def output_unused_attributes output = [] @table_info.each do |table_info| table_info.attributes.sort_by(&:name).each do |attribute| next unless attribute.empty? output << { model: table_info.name, attribute: attribute.name } end end output end