Class: OnlineMigrations::BackgroundDataMigrations::DeleteOrphanedRecords
- Inherits:
-
DataMigration
- Object
- DataMigration
- OnlineMigrations::BackgroundDataMigrations::DeleteOrphanedRecords
- Defined in:
- lib/online_migrations/background_data_migrations/delete_orphaned_records.rb
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #collection ⇒ Object
-
#initialize(model_name, associations, _options = {}) ⇒ DeleteOrphanedRecords
constructor
A new instance of DeleteOrphanedRecords.
- #process(record) ⇒ Object
Methods inherited from DataMigration
#after_cancel, #after_complete, #after_pause, #after_resume, #after_start, #after_stop, #around_process, #build_enumerator, collection_batch_size, #count, named
Constructor Details
#initialize(model_name, associations, _options = {}) ⇒ DeleteOrphanedRecords
Returns a new instance of DeleteOrphanedRecords.
9 10 11 12 |
# File 'lib/online_migrations/background_data_migrations/delete_orphaned_records.rb', line 9 def initialize(model_name, associations, = {}) @model = Object.const_get(model_name, false) @associations = associations.map(&:to_sym) end |
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
7 8 9 |
# File 'lib/online_migrations/background_data_migrations/delete_orphaned_records.rb', line 7 def associations @associations end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/online_migrations/background_data_migrations/delete_orphaned_records.rb', line 7 def model @model end |
Instance Method Details
#collection ⇒ Object
14 15 16 |
# File 'lib/online_migrations/background_data_migrations/delete_orphaned_records.rb', line 14 def collection model.unscoped.where.missing(*associations) end |
#process(record) ⇒ Object
18 19 20 |
# File 'lib/online_migrations/background_data_migrations/delete_orphaned_records.rb', line 18 def process(record) record.destroy end |