gitlab-org--gitlab-foss/app/models/concerns/stepable.rb
Reuben Pereira 0d84010d1c Don't use transactions and exceptions
Instead return error objects.
2019-07-16 19:20:43 +00:00

35 lines
577 B
Ruby

# frozen_string_literal: true
module Stepable
extend ActiveSupport::Concern
def steps
self.class._all_steps
end
def execute_steps
initial_result = {}
steps.inject(initial_result) do |previous_result, callback|
result = method(callback).call
if result[:status] == :error
result[:failed_step] = callback
break result
end
previous_result.merge(result)
end
end
class_methods do
def _all_steps
@_all_steps ||= []
end
def steps(*methods)
_all_steps.concat methods
end
end
end