Sha256: 37562642c5c07e84f31c54a986b781a98ca470d73f9ae394a0f011675c341615

Contents?: true

Size: 678 Bytes

Versions: 19

Compression:

Stored size: 678 Bytes

Contents

class BMC::CollectionUpdate
  extend AttrExtras.mixin

  attr_reader_initialize :scope, :params_array

  def self.call(...)
    new(...).call
  end

  def call
    return update
  end

  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

  def update
    update!
  rescue ActiveRecord::RecordInvalid
    false
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bmc-1.6.1 app/libs/bmc/collection_update.rb
bmc-1.6.0 app/libs/bmc/collection_update.rb
bmc-1.5.1 app/libs/bmc/collection_update.rb
bmc-1.5.0 app/libs/bmc/collection_update.rb
bmc-1.4.3 app/libs/bmc/collection_update.rb
bmc-1.4.2 app/libs/bmc/collection_update.rb
bmc-1.4.1 app/libs/bmc/collection_update.rb
bmc-1.4.0 app/libs/bmc/collection_update.rb
bmc-1.3.5 app/libs/bmc/collection_update.rb
bmc-1.3.4 app/libs/bmc/collection_update.rb
bmc-1.3.3 app/libs/bmc/collection_update.rb
bmc-1.3.2 app/libs/bmc/collection_update.rb
bmc-1.3.1 app/libs/bmc/collection_update.rb
bmc-1.3.0 app/libs/bmc/collection_update.rb
bmc-1.2.1 app/libs/bmc/collection_update.rb
bmc-1.2.0 app/libs/bmc/collection_update.rb
bmc-1.1.0 app/libs/bmc/collection_update.rb
bmc-1.0.1 app/libs/bmc/collection_update.rb
bmc-1.0.0 app/libs/bmc/collection_update.rb