Sha256: c3d43848f48db2bb94977e571027b5efd56315f5ba0eecf4b1d2ab1f084a52f9

Contents?: true

Size: 876 Bytes

Versions: 22

Compression:

Stored size: 876 Bytes

Contents

module Katello
  class BulkItemsHelper
    attr_reader :bulk_params, :model_scope, :key

    def initialize(bulk_params:, model_scope:, key: :id)
      @bulk_params = bulk_params

      if @bulk_params.is_a?(String)
        @bulk_params = ActiveSupport::JSON.decode(@bulk_params).
                      deep_symbolize_keys
      end

      @model_scope = model_scope
      @key = key
    end

    def fetch
      params = bulk_params
      params[:included] ||= {}
      params[:excluded] ||= {}

      items = model_scope
      if params[:included][:ids]
        items = model_scope.where(key => params[:included][:ids])
      elsif params[:included][:search]
        items = model_scope.search_for(params[:included][:search])
      end
      if params[:excluded][:ids]
        items = items.where.not(key => params[:excluded][:ids])
      end

      items
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
katello-4.4.2.2 app/services/katello/bulk_items_helper.rb
katello-4.4.2.1 app/services/katello/bulk_items_helper.rb
katello-4.4.2 app/services/katello/bulk_items_helper.rb
katello-4.5.1 app/services/katello/bulk_items_helper.rb
katello-4.6.0 app/services/katello/bulk_items_helper.rb
katello-4.6.0.rc2 app/services/katello/bulk_items_helper.rb
katello-4.6.0.rc1 app/services/katello/bulk_items_helper.rb
katello-4.5.0 app/services/katello/bulk_items_helper.rb
katello-4.5.0.rc2 app/services/katello/bulk_items_helper.rb
katello-4.4.1 app/services/katello/bulk_items_helper.rb
katello-4.5.0.rc1 app/services/katello/bulk_items_helper.rb
katello-4.4.0.2 app/services/katello/bulk_items_helper.rb
katello-4.4.0.1 app/services/katello/bulk_items_helper.rb
katello-4.3.1 app/services/katello/bulk_items_helper.rb
katello-4.4.0 app/services/katello/bulk_items_helper.rb
katello-4.4.0.rc2 app/services/katello/bulk_items_helper.rb
katello-4.4.0.rc1 app/services/katello/bulk_items_helper.rb
katello-4.3.0 app/services/katello/bulk_items_helper.rb
katello-4.3.0.rc4 app/services/katello/bulk_items_helper.rb
katello-4.3.0.rc3 app/services/katello/bulk_items_helper.rb