Class: Bulky::Updater
- Inherits:
-
Object
- Object
- Bulky::Updater
- Defined in:
- lib/bulky/updater.rb
Instance Attribute Summary collapse
-
#bulk_update ⇒ Object
readonly
Returns the value of attribute bulk_update.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(model, bulk_update_id) ⇒ Updater
constructor
A new instance of Updater.
- #log ⇒ Object
- #strong_updates ⇒ Object
- #update! ⇒ Object
- #updates ⇒ Object
Constructor Details
#initialize(model, bulk_update_id) ⇒ Updater
Returns a new instance of Updater.
6 7 8 9 |
# File 'lib/bulky/updater.rb', line 6 def initialize(model, bulk_update_id) @bulk_update = Bulky::BulkUpdate.find(bulk_update_id) @model = model end |
Instance Attribute Details
#bulk_update ⇒ Object (readonly)
Returns the value of attribute bulk_update.
4 5 6 |
# File 'lib/bulky/updater.rb', line 4 def bulk_update @bulk_update end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/bulky/updater.rb', line 4 def model @model end |
Instance Method Details
#log ⇒ Object
11 12 13 |
# File 'lib/bulky/updater.rb', line 11 def log @log ||= bulk_update.updated_records.build { |r| r.updatable = model } end |
#strong_updates ⇒ Object
15 16 17 |
# File 'lib/bulky/updater.rb', line 15 def strong_updates ActionController::Parameters.new(bulk_update.updates) end |
#update! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bulky/updater.rb', line 23 def update! 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 |
#updates ⇒ Object
19 20 21 |
# File 'lib/bulky/updater.rb', line 19 def updates @updates ||= strong_updates.permit(*model.bulky_attributes) end |