Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37103 - Update kwargs usage to comply with Ruby 3 #739

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AllCops:
- 'node_modules/**/*'
- 'locale/*'
- 'vendor/**/*'
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7

Lint/ShadowingOuterLocalVariable:
Enabled: false
Expand Down
20 changes: 10 additions & 10 deletions app/models/foreman_tasks/concerns/action_triggering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ def update_action; end
# @override
def destroy_action; end

def save(*args)
dynflow_task_wrap(:save) { super(*args) }
def save(...)
dynflow_task_wrap(:save) { super(...) }
end

def save!(*args)
dynflow_task_wrap(:save) { super(*args) }
def save!(...)
dynflow_task_wrap(:save) { super(...) }
end

def destroy
Expand All @@ -37,14 +37,14 @@ def destroy

# In order to use host.<attribute>_changed?, we must assign_attributes to
# the host record for these update and update! methods.
def update(*args)
assign_attributes(*args)
def update(...)
assign_attributes(...)
dynflow_task_wrap(:save) { save }
end
alias update_attributes update

def update!(*args)
assign_attributes(*args)
def update!(...)
assign_attributes(...)
dynflow_task_wrap(:save) { save! }
end
alias update_attributes! update!
Expand Down Expand Up @@ -88,9 +88,9 @@ def plan_hook_action
# We do it separately from the execution phase, because the transaction
# of planning phase is expected to be commited when execution occurs. Also
# we want to be able to rollback the whole db operation when planning fails.
def plan_action(action_class, *args)
def plan_action(action_class, *args, **kwargs)
return if ForemanTasks.dynflow.config.disable_active_record_actions
@execution_plan = ::ForemanTasks.dynflow.world.plan(action_class, *args)
@execution_plan = ::ForemanTasks.dynflow.world.plan(action_class, *args, **kwargs)
raise @execution_plan.errors.first if @execution_plan.error?
end

Expand Down
20 changes: 10 additions & 10 deletions lib/foreman_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def self.dynflow
@dynflow ||= ForemanTasks::Dynflow.new(nil, ForemanTasks::Dynflow::Configuration.new)
end

def self.trigger(action, *args, &block)
dynflow.world.trigger action, *args, &block
def self.trigger(action, *args, **kwargs, &block)
dynflow.world.trigger action, *args, **kwargs, &block
end

def self.trigger_task(async, action, *args, &block)
def self.trigger_task(async, action, *args, **kwargs, &block)
rails_safe_trigger_task do
Match! async, true, false
match trigger(action, *args, &block),
match trigger(action, *args, **kwargs, &block),
(on ::Dynflow::World::PlaningFailed.call(error: ~any) do |error|
raise error
end),
Expand All @@ -47,18 +47,18 @@ def self.rails_safe_trigger_task
end
end

def self.async_task(action, *args, &block)
trigger_task true, action, *args, &block
def self.async_task(action, *args, **kwargs, &block)
trigger_task true, action, *args, **kwargs, &block
end

def self.sync_task(action, *args, &block)
trigger_task(false, action, *args, &block).tap do |task|
def self.sync_task(action, *args, **kwargs, &block)
trigger_task(false, action, *args, **kwargs, &block).tap do |task|
raise TaskError, task if task.execution_plan.error? || task.execution_plan.result == :warning
end
end

def self.delay(action, delay_options, *args)
result = dynflow.world.delay action, delay_options, *args
def self.delay(action, delay_options, *args, **kwargs)
result = dynflow.world.delay action, delay_options, *args, **kwargs
ForemanTasks::Task::DynflowTask.where(:external_id => result.id).first!
end

Expand Down