Class: Katello::BulkItemsHelper

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/bulk_items_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bulk_params:, model_scope:, key: :id) ⇒ BulkItemsHelper

Returns a new instance of BulkItemsHelper.



5
6
7
8
9
10
11
12
13
14
15
# File 'app/services/katello/bulk_items_helper.rb', line 5

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

Instance Attribute Details

#bulk_paramsObject (readonly)

Returns the value of attribute bulk_params.



3
4
5
# File 'app/services/katello/bulk_items_helper.rb', line 3

def bulk_params
  @bulk_params
end

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'app/services/katello/bulk_items_helper.rb', line 3

def key
  @key
end

#model_scopeObject (readonly)

Returns the value of attribute model_scope.



3
4
5
# File 'app/services/katello/bulk_items_helper.rb', line 3

def model_scope
  @model_scope
end

Instance Method Details

#fetchObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/katello/bulk_items_helper.rb', line 17

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

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

  items
end