Class: AttributeStats::StatsGenerator
- Inherits:
-
Object
- Object
- AttributeStats::StatsGenerator
- 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
-
#migration ⇒ Object
readonly
Returns the value of attribute migration.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#table_info ⇒ Object
readonly
Returns the value of attribute table_info.
Instance Method Summary collapse
- #attribute_usage ⇒ Object
- #dormant_tables ⇒ Object
- #generate_migration ⇒ Object
-
#initialize(opts = {}) ⇒ StatsGenerator
constructor
A new instance of StatsGenerator.
- #inspect ⇒ Object
- #set_formatter(formatter_type) ⇒ Object
- #unused_attribute_references ⇒ Object
- #unused_attributes ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ StatsGenerator
Returns a new instance of 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
#migration ⇒ Object (readonly)
Returns the value of attribute migration.
3 4 5 |
# File 'lib/stats_generation/stats_generator.rb', line 3 def migration @migration end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/stats_generation/stats_generator.rb', line 3 def @options end |
#table_info ⇒ Object (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_usage ⇒ Object
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_tables ⇒ Object
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_migration ⇒ Object
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: ).output_migration end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/stats_generation/stats_generator.rb', line 57 def inspect "StatsGenerator(results: #{table_info.to_s[0..200]}, options: #{})" end |
#set_formatter(formatter_type) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/stats_generation/stats_generator.rb', line 43 def set_formatter(formatter_type) formatter_was = [:formatter] case formatter_type.to_s.downcase when 'json' [:formatter] = :json when 'tabular' [:formatter] = :tabular when 'hash' [:formatter] = :hash end @formatter = nil unless [:formatter] == formatter_was [:formatter] end |
#unused_attribute_references ⇒ Object
37 38 39 40 41 |
# File 'lib/stats_generation/stats_generator.rb', line 37 def unused_attribute_references fetch_empty_attributes SetAttributeReferences.new(table_info: table_info, options: ).execute output formatter.output_attribute_references end |
#unused_attributes ⇒ Object
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 |