Merge pull request #9 from arikarim/dev

Enhance error handling in manager.rb by logging error messages and cl…
This commit is contained in:
Brusk Awat 2025-05-27 14:59:17 +03:00 committed by GitHub
commit 688bcdaaf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 4 deletions

View File

@ -3,7 +3,25 @@
require_relative "workflower/version"
require "workflower/manager"
require "workflower/acts_as_workflower"
module Workflower
class Error < StandardError; end
# Your code goes here...
class << self
def configuration
@configuration ||= Configuration.new
end
def configure
yield(configuration)
end
end
class Configuration
attr_accessor :logger
def initialize
@logger = nil
end
end
end

View File

@ -37,7 +37,6 @@ module Workflower
end
def possible_transitions
# @transitions.where(state: @current_state).where("sequence = :seq OR sequence = :seq_plus", seq: @current_sequence, seq_plus: @current_sequence + 1).order("sequence ASC") || []
@transitions.select do |item|
item[:state] == @current_state && (item[:sequence] == @current_sequence || item[:sequence] == @current_sequence + 1)
end
@ -61,7 +60,11 @@ module Workflower
@calling_model.assign_attributes flow.updateable_attributes(@calling_model)
flow.call_after_transition(@calling_model)
true
rescue Exception
rescue Exception => e
# if the log level is set to debug, we want to log the error
logger = Workflower.configuration.logger
logger.debug("Error during transition: #{e.message}") if logger.present?
@calling_model.errors.add(@calling_model.workflower_state_column_name, :transition_faild)
false
end

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
module Workflower
VERSION = "0.2.6"
VERSION = "0.2.7"
end