Class: DroppableTable::ModelCollector
- Inherits:
-
Object
- Object
- DroppableTable::ModelCollector
- Defined in:
- lib/droppable_table/model_collector.rb
Instance Attribute Summary collapse
-
#models ⇒ Object
readonly
Returns the value of attribute models.
-
#table_mapping ⇒ Object
readonly
Returns the value of attribute table_mapping.
Instance Method Summary collapse
- #collect ⇒ Object
- #habtm_tables ⇒ Object
-
#initialize ⇒ ModelCollector
constructor
A new instance of ModelCollector.
- #sti_base_tables ⇒ Object
- #table_names ⇒ Object
Constructor Details
#initialize ⇒ ModelCollector
9 10 11 12 |
# File 'lib/droppable_table/model_collector.rb', line 9 def initialize @models = [] @table_mapping = {} # model_class => table_name end |
Instance Attribute Details
#models ⇒ Object (readonly)
Returns the value of attribute models.
7 8 9 |
# File 'lib/droppable_table/model_collector.rb', line 7 def models @models end |
#table_mapping ⇒ Object (readonly)
Returns the value of attribute table_mapping.
7 8 9 |
# File 'lib/droppable_table/model_collector.rb', line 7 def table_mapping @table_mapping end |
Instance Method Details
#collect ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/droppable_table/model_collector.rb', line 14 def collect ensure_rails_loaded eager_load_all_models collect_all_descendants build_table_mapping self end |
#habtm_tables ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/droppable_table/model_collector.rb', line 42 def habtm_tables habtm_join_tables = Set.new models.each do |model| next if model.abstract_class? # Find HABTM associations model.reflect_on_all_associations(:has_and_belongs_to_many).each do |association| join_table = association.join_table habtm_join_tables << join_table if join_table end rescue StandardError # Skip models that can't be inspected end habtm_join_tables end |
#sti_base_tables ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/droppable_table/model_collector.rb', line 27 def sti_base_tables sti_tables = Set.new models.each do |model| next if model.abstract_class? # Check if this model uses STI (has a 'type' column) sti_tables << model.table_name if model.columns_hash.key?("type") && model.base_class == model rescue StandardError # Skip models that can't be inspected end sti_tables end |
#table_names ⇒ Object
23 24 25 |
# File 'lib/droppable_table/model_collector.rb', line 23 def table_names Set.new(table_mapping.values) end |