Sha256: cdd3d4110430b598710a2cf16d11bfcd14020de678e42995594e2ff7b4af8376

Contents?: true

Size: 616 Bytes

Versions: 7

Compression:

Stored size: 616 Bytes

Contents

class Agilibox::CollectionUpdate < Agilibox::Service
  initialize_with :scope, :params_array

  def call
    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

7 entries across 7 versions & 1 rubygems

Version Path
agilibox-1.3.4 app/libs/agilibox/collection_update.rb
agilibox-1.3.3 app/libs/agilibox/collection_update.rb
agilibox-1.3.2 app/libs/agilibox/collection_update.rb
agilibox-1.3.1 app/libs/agilibox/collection_update.rb
agilibox-1.3.0 app/libs/agilibox/collection_update.rb
agilibox-1.2.3 app/libs/agilibox/collection_update.rb
agilibox-1.2.2 app/libs/agilibox/collection_update.rb