Sha256: 3692271cfe991e84c9d45991caf3816a5c1048380a3c395c49ae19fe16327cc6

Contents?: true

Size: 913 Bytes

Versions: 5

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true

module RailsWorkflow
  # Stores error information
  class Error < ActiveRecord::Base
    include HasContext
    belongs_to :parent, polymorphic: true, required: false
    scope :unresolved, -> { where('resolved is null or resolved = false') }

    delegate :data, to: :context
    delegate :retry, to: :error_resolver

    def can_restart_process?
      process.unresolved_errors.count.zero?
    end

    def target
      data[:target]
    end

    def operation
      parent if parent.is_a? RailsWorkflow::Operation
    end

    def process
      if operation
        operation.process
      elsif target.is_a? RailsWorkflow::Process
        target
      elsif parent.is_a? RailsWorkflow::Process
        parent
      end
    end

    def config
      RailsWorkflow.config
    end

    def error_resolver
      @error_resolver ||= config.error_resolver.new(self)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_workflow-0.7.3 app/models/rails_workflow/error.rb
rails_workflow-0.7.2 app/models/rails_workflow/error.rb
rails_workflow-0.7.1 app/models/rails_workflow/error.rb
rails_workflow-0.7.0 app/models/rails_workflow/error.rb
rails_workflow-0.4.4 app/models/rails_workflow/error.rb