Class: OnlineMigrations::BackgroundMigrations::PerformActionOnRelation
- Inherits:
-
OnlineMigrations::BackgroundMigration
- Object
- OnlineMigrations::BackgroundMigration
- OnlineMigrations::BackgroundMigrations::PerformActionOnRelation
- Defined in:
- lib/online_migrations/background_migrations/perform_action_on_relation.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(model_name, conditions, action, options = {}) ⇒ PerformActionOnRelation
constructor
A new instance of PerformActionOnRelation.
- #process_batch(relation) ⇒ Object
- #relation ⇒ Object
Methods inherited from OnlineMigrations::BackgroundMigration
Constructor Details
#initialize(model_name, conditions, action, options = {}) ⇒ PerformActionOnRelation
Returns a new instance of PerformActionOnRelation.
9 10 11 12 13 14 |
# File 'lib/online_migrations/background_migrations/perform_action_on_relation.rb', line 9 def initialize(model_name, conditions, action, = {}) @model = Object.const_get(model_name, false) @conditions = conditions @action = action.to_sym @options = .symbolize_keys end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
7 8 9 |
# File 'lib/online_migrations/background_migrations/perform_action_on_relation.rb', line 7 def action @action end |
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
7 8 9 |
# File 'lib/online_migrations/background_migrations/perform_action_on_relation.rb', line 7 def conditions @conditions end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/online_migrations/background_migrations/perform_action_on_relation.rb', line 7 def model @model end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/online_migrations/background_migrations/perform_action_on_relation.rb', line 7 def @options end |
Instance Method Details
#process_batch(relation) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/online_migrations/background_migrations/perform_action_on_relation.rb', line 20 def process_batch(relation) case action when :update_all updates = .fetch(:updates) relation.public_send(action, updates) when :delete_all, :destroy_all relation.public_send(action) else relation.each(&action) end end |
#relation ⇒ Object
16 17 18 |
# File 'lib/online_migrations/background_migrations/perform_action_on_relation.rb', line 16 def relation model.unscoped.where(conditions) end |