diff --git a/lib/auxiliary_rails/application/error.rb b/lib/auxiliary_rails/application/error.rb index 50896ae..3e9e43f 100644 --- a/lib/auxiliary_rails/application/error.rb +++ b/lib/auxiliary_rails/application/error.rb @@ -3,24 +3,24 @@ module Application # @abstract class Error < RuntimeError attr_accessor :context - attr_reader :exception, :severity + attr_reader :exc, :severity class << self def i18n_scope "errors.#{name.underscore}" end - # @return [self] Wraps exception into a new Application Error object - def wrap(exception, context: {}, severity: nil) - new(exception.message, context: context, exception: exception, severity: severity) + # @return [self] Wraps exception into a new ApplicationError object + def wrap(exc, context: {}, severity: nil) + new(exc.message, context: context, exc: exc, severity: severity) end end - def initialize(message = nil, context: {}, exception: nil, severity: nil) - super message + def initialize(message = nil, context: {}, exc: nil, severity: nil) + super(message) self.context = default_context.merge(context || {}) - self.exception = exception + self.exc = exc self.severity = severity&.to_sym || default_severity end @@ -44,7 +44,7 @@ def report protected - attr_writer :exception, :severity + attr_writer :exc, :severity end end end diff --git a/lib/auxiliary_rails/concerns/performable.rb b/lib/auxiliary_rails/concerns/performable.rb index 8f27312..81f0683 100644 --- a/lib/auxiliary_rails/concerns/performable.rb +++ b/lib/auxiliary_rails/concerns/performable.rb @@ -73,19 +73,19 @@ def on(status, &block) def ensure_empty_errors! return if errors.empty? - error!("`#{self.class}` contains errors.") + error!("'#{self.class}' contains errors.") end def ensure_empty_status! return if performable_status.nil? - error!("`#{self.class}` was already executed.") + error!("'#{self.class}' was already executed.") end def ensure_execution! return if performable_status.present? - error!("`#{self.class}` was not executed yet.") + error!("'#{self.class}' was not executed yet.") end # Sets command's status to failure. diff --git a/spec/sample_commands_spec.rb b/spec/sample_commands_spec.rb index f8f3792..dadc81d 100644 --- a/spec/sample_commands_spec.rb +++ b/spec/sample_commands_spec.rb @@ -29,7 +29,7 @@ describe '#call' do it do expect { cmd.call }.to raise_error AuxiliaryRails::Application::Error, - '`SampleCommands::DoubleStatusSetCommand` was already executed.' + "'SampleCommands::DoubleStatusSetCommand' was already executed." end end end @@ -40,7 +40,7 @@ describe '#call' do it do expect { cmd.call }.to raise_error AuxiliaryRails::Application::Error, - '`SampleCommands::SuccessWithErrorsCommand` contains errors.' + "'SampleCommands::SuccessWithErrorsCommand' contains errors." end end end