Class: AttributeStats::StatsGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/stats_generation/stats_generator.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
      consider_defaults_unused: true,
                      defaults: false,
                     formatter: :hash,
 source: :code,
             dormant_table_age: '3.months.ago',
verbose: false }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ StatsGenerator



13
14
15
# File 'lib/stats_generation/stats_generator.rb', line 13

def initialize(opts={})
  @options = DEFAULT_OPTIONS.merge(opts)
end

Instance Attribute Details

#migrationObject (readonly)

Returns the value of attribute migration.



3
4
5
# File 'lib/stats_generation/stats_generator.rb', line 3

def migration
  @migration
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/stats_generation/stats_generator.rb', line 3

def options
  @options
end

#table_infoObject (readonly)

Returns the value of attribute table_info.



3
4
5
# File 'lib/stats_generation/stats_generator.rb', line 3

def table_info
  @table_info
end

Instance Method Details

#attribute_usageObject



17
18
19
20
# File 'lib/stats_generation/stats_generator.rb', line 17

def attribute_usage
  fetch_attribute_usage
  output formatter.output_all_attributes
end

#dormant_tablesObject



22
23
24
25
# File 'lib/stats_generation/stats_generator.rb', line 22

def dormant_tables
  fetch_dormant_tables
  output formatter.output_dormant_tables
end

#generate_migrationObject



32
33
34
35
# File 'lib/stats_generation/stats_generator.rb', line 32

def generate_migration
  fetch_empty_attributes
  GenerateMigration.new(table_info: table_info, options: options).output_migration
end

#inspectObject



51
52
53
# File 'lib/stats_generation/stats_generator.rb', line 51

def inspect
  "StatsGenerator(results: #{table_info.to_s[0..200]}, options: #{options})"
end

#set_formatter(formatter_type) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stats_generation/stats_generator.rb', line 37

def set_formatter(formatter_type)
  formatter_was = options[:formatter]
  case formatter_type.to_s.downcase
  when 'json'
    options[:formatter] = :json
  when 'tabular'
    options[:formatter] = :tabular
  when 'hash'
    options[:formatter] = :hash
  end
  @formatter = nil unless options[:formatter] == formatter_was
  options[:formatter]
end

#unused_attributesObject



27
28
29
30
# File 'lib/stats_generation/stats_generator.rb', line 27

def unused_attributes
  fetch_empty_attributes
  output formatter.output_unused_attributes
end