Class: Katello::BulkItemsHelper
- Inherits:
-
Object
- Object
- Katello::BulkItemsHelper
- Defined in:
- app/services/katello/bulk_items_helper.rb
Instance Attribute Summary collapse
-
#bulk_params ⇒ Object
readonly
Returns the value of attribute bulk_params.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#model_scope ⇒ Object
readonly
Returns the value of attribute model_scope.
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(bulk_params:, model_scope:, key: :id) ⇒ BulkItemsHelper
constructor
A new instance of BulkItemsHelper.
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_params ⇒ Object (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 |
#key ⇒ Object (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_scope ⇒ Object (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
#fetch ⇒ Object
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 |