class RailsWorkflow::ErrorBuilder

Default error builder. Can be changed in configuration. Manages errors building

Attributes

context[RW]
exception[RW]

Public Class Methods

handle(exception, context) click to toggle source
# File lib/rails_workflow/error_builder.rb, line 9
def self.handle(exception, context)
  new(exception, context).handle
end
new(exception, context) click to toggle source
# File lib/rails_workflow/error_builder.rb, line 13
def initialize(exception, context)
  @exception = exception
  @context = context
end

Public Instance Methods

handle() click to toggle source
# File lib/rails_workflow/error_builder.rb, line 18
def handle
  create_error(context)
  process_parent(target)
end

Private Instance Methods

create_error(context) click to toggle source
# File lib/rails_workflow/error_builder.rb, line 25
def create_error(context)
  error = RailsWorkflow::Error.create(
    parent: target,
    message: exception.message.first(250),
    stack_trace: exception.backtrace.join("<br/>\n")
  )

  error.create_context(data: context)
end
process_parent(subject) click to toggle source
# File lib/rails_workflow/error_builder.rb, line 49
def process_parent(subject)
  return if subject.nil?

  subject.status = Status::ERROR
  subject.save!
  process_parent(subject.parent) if subject.parent.present?
end
target() click to toggle source

Changing custom process or operation classes to default classes. If we store error with a custom class and somebody will delete or rename this class - we will not be able to load error.

# File lib/rails_workflow/error_builder.rb, line 38
def target
  @target ||= begin
    parent = context[:parent]
    if parent.is_a? RailsWorkflow::Operation
      parent.becomes(RailsWorkflow::Operation)
    elsif parent.is_a? RailsWorkflow::Process
      parent.becomes(RailsWorkflow::Process)
    end
  end
end