Module: Godmin::Resources::ResourceService::BatchActions

Extended by:
ActiveSupport::Concern
Included in:
Godmin::Resources::ResourceService
Defined in:
lib/godmin/resources/resource_service/batch_actions.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#batch_action(action, records) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/godmin/resources/resource_service/batch_actions.rb', line 9

def batch_action(action, records)
  if batch_action?(action)
    send("batch_action_#{action}", records)
    true
  else
    false
  end
end

#batch_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/godmin/resources/resource_service/batch_actions.rb', line 18

def batch_action?(action)
  batch_action_map.key?(action.to_sym)
end

#include_batch_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/godmin/resources/resource_service/batch_actions.rb', line 22

def include_batch_action?(action)
  options = batch_action_map[action.to_sym]

  (options[:only].nil? && options[:except].nil?) ||
    (options[:only] && options[:only].include?(scope.to_sym)) ||
    (options[:except] && !options[:except].include?(scope.to_sym))
end

#include_batch_actions?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/godmin/resources/resource_service/batch_actions.rb', line 30

def include_batch_actions?
  batch_action_map.keys.any? do |action|
    include_batch_action?(action)
  end
end