Class: DroppableTable::Analyzer
- Inherits:
-
Object
- Object
- DroppableTable::Analyzer
- Defined in:
- lib/droppable_table/analyzer.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#droppable_tables ⇒ Object
readonly
Returns the value of attribute droppable_tables.
-
#excluded_tables ⇒ Object
readonly
Returns the value of attribute excluded_tables.
-
#habtm_tables ⇒ Object
readonly
Returns the value of attribute habtm_tables.
-
#model_tables ⇒ Object
readonly
Returns the value of attribute model_tables.
-
#schema_tables ⇒ Object
readonly
Returns the value of attribute schema_tables.
-
#sti_base_tables ⇒ Object
readonly
Returns the value of attribute sti_base_tables.
Instance Method Summary collapse
- #analyze ⇒ Object
-
#initialize(config = nil) ⇒ Analyzer
constructor
A new instance of Analyzer.
- #report(format: :text) ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ Analyzer
Returns a new instance of Analyzer.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/droppable_table/analyzer.rb', line 11 def initialize(config = nil) @config = config.is_a?(Config) ? config : Config.new(config) @schema_tables = {} # DB name => array of table info @model_tables = Set.new # Table names with corresponding models @sti_base_tables = Set.new # STI base tables @habtm_tables = Set.new # HABTM join tables @droppable_tables = [] # Potentially droppable tables @excluded_tables = @config.all_excluded_tables # Rails internal + gems + user defined @model_collector = nil @schema_format = nil end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/droppable_table/analyzer.rb', line 8 def config @config end |
#droppable_tables ⇒ Object (readonly)
Returns the value of attribute droppable_tables.
8 9 10 |
# File 'lib/droppable_table/analyzer.rb', line 8 def droppable_tables @droppable_tables end |
#excluded_tables ⇒ Object (readonly)
Returns the value of attribute excluded_tables.
8 9 10 |
# File 'lib/droppable_table/analyzer.rb', line 8 def excluded_tables @excluded_tables end |
#habtm_tables ⇒ Object (readonly)
Returns the value of attribute habtm_tables.
8 9 10 |
# File 'lib/droppable_table/analyzer.rb', line 8 def habtm_tables @habtm_tables end |
#model_tables ⇒ Object (readonly)
Returns the value of attribute model_tables.
8 9 10 |
# File 'lib/droppable_table/analyzer.rb', line 8 def model_tables @model_tables end |
#schema_tables ⇒ Object (readonly)
Returns the value of attribute schema_tables.
8 9 10 |
# File 'lib/droppable_table/analyzer.rb', line 8 def schema_tables @schema_tables end |
#sti_base_tables ⇒ Object (readonly)
Returns the value of attribute sti_base_tables.
8 9 10 |
# File 'lib/droppable_table/analyzer.rb', line 8 def sti_base_tables @sti_base_tables end |
Instance Method Details
#analyze ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/droppable_table/analyzer.rb', line 23 def analyze check_migration_status # Check for pending migrations detect_schema_format # Detect schema.rb vs structure.sql collect_schema_tables # Collect tables from all schema files eager_load_models # Ensure all models are loaded collect_model_tables # Collect from ActiveRecord::Base.descendants collect_sti_tables # Detect STI hierarchies collect_habtm_tables # Detect HABTM associations identify_droppable_tables # Identify droppable tables self end |
#report(format: :text) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/droppable_table/analyzer.rb', line 36 def report(format: :text) # TODO: Implement report generation case format when :json generate_json_report else generate_text_report end end |