Sha256: bf964bf602a79d70bb9a99f92295d3a8be19282af9cad53617012af868308e0f

Contents?: true

Size: 649 Bytes

Versions: 56

Compression:

Stored size: 649 Bytes

Contents

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

  def call
    update # rubocop:disable Rails/SaveBang
  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

56 entries across 56 versions & 1 rubygems

Version Path
agilibox-2.0.0 app/libs/agilibox/collection_update.rb
agilibox-1.11.0 app/libs/agilibox/collection_update.rb
agilibox-1.10.5 app/libs/agilibox/collection_update.rb
agilibox-1.10.2 app/libs/agilibox/collection_update.rb
agilibox-1.10.1 app/libs/agilibox/collection_update.rb
agilibox-1.10.0 app/libs/agilibox/collection_update.rb
agilibox-1.9.20 app/libs/agilibox/collection_update.rb
agilibox-1.9.19 app/libs/agilibox/collection_update.rb
agilibox-1.9.18 app/libs/agilibox/collection_update.rb
agilibox-1.9.17 app/libs/agilibox/collection_update.rb
agilibox-1.9.16 app/libs/agilibox/collection_update.rb
agilibox-1.9.15 app/libs/agilibox/collection_update.rb
agilibox-1.9.14 app/libs/agilibox/collection_update.rb
agilibox-1.9.13 app/libs/agilibox/collection_update.rb
agilibox-1.9.12 app/libs/agilibox/collection_update.rb
agilibox-1.9.11 app/libs/agilibox/collection_update.rb
agilibox-1.9.10 app/libs/agilibox/collection_update.rb
agilibox-1.9.9 app/libs/agilibox/collection_update.rb
agilibox-1.9.8 app/libs/agilibox/collection_update.rb
agilibox-1.9.7 app/libs/agilibox/collection_update.rb