Sha256: f78a28c6a9abd37f8993356f47148657b336a6f33116dd248aba51c7801e3049

Contents?: true

Size: 1016 Bytes

Versions: 3

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

require_relative 'handler'

module ChainOfResp
  # @abstract
  class AbstractHandler < ChainOfResp::Handler
    # @return [Handler]
    attr_reader :stop_process_on_failure, :stop_process_on_success
    attr_accessor :handler, :result

    def initialize(opts = {})
      @stop_process_on_failure = opts[:stop_process_on_failure] || false
      @stop_process_on_success = opts[:stop_process_on_success] || false
      @next_handler = nil
      post_initialize(opts) # implemented in subclass
    end

    # @param [Handler] handler
    #
    # @return [Handler]
    def next_handler(handler)
      @handler = handler if handler

      handler
    end

    # @abstract
    #
    # @param [String] request
    #
    # @return [Boolean, nil]
    def handle(request)
      check = check_value(request) # imlemented in subclass
      return true  if check && stop_process_on_success

      return false if !check && stop_process_on_failure

      handler&.handle(request)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
checkability-0.6.2 lib/checkability/chain_of_resp/abstract_handler.rb
checkability-0.6.1 lib/checkability/chain_of_resp/abstract_handler.rb
checkability-0.6.0 lib/checkability/chain_of_resp/abstract_handler.rb