diff --git a/lib/workflower.rb b/lib/workflower.rb index e8232ee..88aaf24 100644 --- a/lib/workflower.rb +++ b/lib/workflower.rb @@ -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 diff --git a/lib/workflower/manager.rb b/lib/workflower/manager.rb index 5d6f02b..95b75c3 100644 --- a/lib/workflower/manager.rb +++ b/lib/workflower/manager.rb @@ -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 diff --git a/lib/workflower/version.rb b/lib/workflower/version.rb index 95767ed..986ba7d 100644 --- a/lib/workflower/version.rb +++ b/lib/workflower/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Workflower - VERSION = "0.2.6" + VERSION = "0.2.7" end