Class: Bulky::Updater
- Inherits:
-
Object
- Object
- Bulky::Updater
- Defined in:
- lib/bulky/updater.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(model, bulk_update_id) ⇒ Updater
constructor
A new instance of Updater.
- #update! ⇒ Object
Constructor Details
#initialize(model, bulk_update_id) ⇒ Updater
Returns a new instance of Updater.
9 10 11 12 13 |
# File 'lib/bulky/updater.rb', line 9 def initialize(model, bulk_update_id) @bulk_update = Bulky::BulkUpdate.find(bulk_update_id) @model = model @updates = @bulk_update.updates end |
Class Method Details
.perform(model_name, update_id, bulk_update_id) ⇒ Object
4 5 6 7 |
# File 'lib/bulky/updater.rb', line 4 def self.perform(model_name, update_id, bulk_update_id) model = model_name.constantize.find(update_id) new(model, bulk_update_id).update! end |
Instance Method Details
#update! ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bulky/updater.rb', line 15 def update! @model.tap do @log = @bulk_update.updated_records.build { |r| r.updatable = @model } begin @model.attributes = @updates @log.updatable_changes = @model.changes @model.save! rescue => e @log. = e. @log.error_backtrace = e.backtrace.join("\n") raise e ensure @log.save! end end end |