Class: Actions::BulkAction
- Inherits:
-
ActionWithSubPlans
- Object
- Dynflow::Action
- Base
- EntryAction
- ActionWithSubPlans
- Actions::BulkAction
- Defined in:
- app/lib/actions/bulk_action.rb
Instance Method Summary collapse
- #check_targets!(targets) ⇒ Object
- #create_sub_plans ⇒ Object
- #humanized_input ⇒ Object
- #humanized_name ⇒ Object
-
#plan(action_class, targets, *args) ⇒ Object
Parameters: actions_class:: Class of action to trigger on targets targets:: Array of objects on which the action_class should be triggered *args:: Arguments that all the targets share.
- #rescue_strategy ⇒ Object
- #run(event = nil) ⇒ Object
Methods inherited from ActionWithSubPlans
#humanized_output, #run_progress
Methods inherited from EntryAction
#action_subject, all_action_names, #delay, #resource_locks, serializer_class
Methods included from Helpers::Lock
#exclusive_lock!, #link!, #lock!
Methods included from Helpers::ArgsSerialization
Methods inherited from Base
#already_running?, #humanized_errors, #humanized_output, #serializer_class, #task, #task_input, #task_output
Instance Method Details
#check_targets!(targets) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'app/lib/actions/bulk_action.rb', line 55 def check_targets!(targets) if targets.empty? fail ::Foreman::Exception.new(N_("Empty bulk action")) end if targets.map(&:class).uniq.length > 1 fail ::Foreman::Exception.new(N_("The targets are of different types")) end end |
#create_sub_plans ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'app/lib/actions/bulk_action.rb', line 45 def create_sub_plans action_class = input[:action_class].constantize target_class = input[:target_class].constantize targets = target_class.where(:id => input[:target_ids]) targets.map do |target| trigger(action_class, target, *input[:args]) end end |
#humanized_input ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/lib/actions/bulk_action.rb', line 35 def humanized_input a_sub_task = task.sub_tasks.first if a_sub_task [a_sub_task.humanized[:action].to_s.downcase] + Array(a_sub_task.humanized[:input]) + ['...'] end end |
#humanized_name ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/lib/actions/bulk_action.rb', line 23 def humanized_name if task.sub_tasks.first task.sub_tasks.first.humanized[:action] else _("Bulk action") end end |
#plan(action_class, targets, *args) ⇒ Object
Parameters:
- actions_class
-
Class of action to trigger on targets
- targets
-
Array of objects on which the action_class should be triggered
- *args
-
Arguments that all the targets share
11 12 13 14 15 16 17 |
# File 'app/lib/actions/bulk_action.rb', line 11 def plan(action_class, targets, *args) check_targets!(targets) plan_self(:action_class => action_class.to_s, :target_ids => targets.map(&:id), :target_class => targets.first.class.to_s, :args => args) end |
#rescue_strategy ⇒ Object
31 32 33 |
# File 'app/lib/actions/bulk_action.rb', line 31 def rescue_strategy Dynflow::Action::Rescue::Skip end |
#run(event = nil) ⇒ Object
19 20 21 |
# File 'app/lib/actions/bulk_action.rb', line 19 def run(event = nil) super unless event == Dynflow::Action::Skip end |