Sha256: 0d60b9396df06b10892e878f5031d365faeeba424467f867dca93dab183c9db4

Contents?: true

Size: 1.63 KB

Versions: 40

Compression:

Stored size: 1.63 KB

Contents

module Eco
  module API
    module Common
      module Loaders
        class ErrorHandler < Eco::API::Common::Loaders::CaseBase
          class << self
            attr_writer :error

            # @return [Eco::API::Error] the error class, child of `Eco::API::Error`.
            def error(value = nil)
              unless value
                msg = "You should specify an error type for #{self.class}"
                return @error || (raise msg)
              end
              @error = value
            end
          end

          inheritable_class_vars :error

          def initialize(handlers) # rubocop:disable Lint/MissingSuper
            msg = "Expected Eco::API::Policies. Given #{handlers.class}"
            raise msg unless handlers.is_a?(Eco::API::Error::Handlers)

            handlers.on(error, &method(:main))
          end

          # @param people [Eco::API::Organization::People] the people in the queue of the current `job`
          # @param session [Eco::API::Session] the current session where the usecase kicks in.
          # @param options [Hash] the options that modify the case behaviour or bring some dependencies.
          # @param handler [Eco::API::Error::Hanlder] the `error handler` instance object.
          # @param job [Eco::API::Session::Batch::Job] the `Batch::Job` made on purpose for this handler.
          def main(people, session, options, handler, job) # rubocop:disable Lint/UnusedMethodArgument
            raise "You should implement this method"
          end

          def error
            self.class.error
          end
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.20 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.19 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.18 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.17 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.16 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.15 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.14 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.13 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.12 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.11 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.10 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.9 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.8 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.7 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.6 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.5 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.4 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.3 lib/eco/api/common/loaders/error_handler.rb
eco-helpers-3.0.2 lib/eco/api/common/loaders/error_handler.rb