Class: BMC::CollectionUpdate
- Inherits:
-
Object
- Object
- BMC::CollectionUpdate
- Defined in:
- app/libs/bmc/collection_update.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.call ⇒ Object
6 7 8 |
# File 'app/libs/bmc/collection_update.rb', line 6 def self.call(...) new(...).call end |
Instance Method Details
#call ⇒ Object
10 11 12 |
# File 'app/libs/bmc/collection_update.rb', line 10 def call return update end |
#update ⇒ Object
33 34 35 36 37 |
# File 'app/libs/bmc/collection_update.rb', line 33 def update update! rescue ActiveRecord::RecordInvalid false end |
#update! ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/libs/bmc/collection_update.rb', line 14 def update! ApplicationRecord.transaction do params_array.each do |object_param| if object_param[:id].present? object = scope.find(object_param[:id]) else object = scope.new end if object_param.delete(:_destroy).to_i == 1 object.destroy! else object.update!(object_param) end end end true end |