Class: AttributeStats::HashFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/formatters/hash_formatter.rb

Direct Known Subclasses

JSONFormatter

Instance Method Summary collapse

Constructor Details

#initialize(options: {}, table_info: {}, migration: []) ⇒ HashFormatter

Returns a new instance of HashFormatter.



4
5
6
# File 'lib/formatters/hash_formatter.rb', line 4

def initialize(options: {}, table_info: {}, migration: [])
  @options, @table_info, @migration = options, table_info, migration
end

Instance Method Details

#output_all_attributesObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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_referencesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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_tablesObject



41
42
43
44
45
46
47
# 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_attributesObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# 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