obstools/healthcheck-endpoint

View on GitHub
lib/healthcheck_endpoint/rack_middleware.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module HealthcheckEndpoint
  class RackMiddleware
    def initialize(
      app,
      resolver = HealthcheckEndpoint::Resolver,
      counfigured = !!HealthcheckEndpoint.configuration
    )
      @app = app
      @resolver = resolver
      @counfigured = counfigured
    end

    def call(env)
      raise HealthcheckEndpoint::Error::Configuration::NotConfigured unless counfigured

      resolver.call(env) || app.call(env)
    end

    private

    attr_reader :app, :resolver, :counfigured
  end
end