Class: OnlineMigrations::BackgroundMigrations::DeleteAssociatedRecords
- Inherits:
-
OnlineMigrations::BackgroundMigration
- Object
- OnlineMigrations::BackgroundMigration
- OnlineMigrations::BackgroundMigrations::DeleteAssociatedRecords
- Defined in:
- lib/online_migrations/background_migrations/delete_associated_records.rb
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize(model_name, record_id, association, _options = {}) ⇒ DeleteAssociatedRecords
constructor
A new instance of DeleteAssociatedRecords.
- #process_batch(relation) ⇒ Object
- #relation ⇒ Object
Methods inherited from OnlineMigrations::BackgroundMigration
Constructor Details
#initialize(model_name, record_id, association, _options = {}) ⇒ DeleteAssociatedRecords
Returns a new instance of DeleteAssociatedRecords.
9 10 11 12 13 |
# File 'lib/online_migrations/background_migrations/delete_associated_records.rb', line 9 def initialize(model_name, record_id, association, = {}) model = Object.const_get(model_name, false) @record = model.find(record_id) @association = association end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
7 8 9 |
# File 'lib/online_migrations/background_migrations/delete_associated_records.rb', line 7 def association @association end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
7 8 9 |
# File 'lib/online_migrations/background_migrations/delete_associated_records.rb', line 7 def record @record end |
Instance Method Details
#process_batch(relation) ⇒ Object
23 24 25 |
# File 'lib/online_migrations/background_migrations/delete_associated_records.rb', line 23 def process_batch(relation) relation.delete_all end |
#relation ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/online_migrations/background_migrations/delete_associated_records.rb', line 15 def relation if !@record.respond_to?(association) raise ArgumentError, "'#{@record.class.name}' has no association called '#{association}'" end record.public_send(association) end |