Class: Scrubber::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/scrubber/middleware.rb,
sig/scrubber_rb.rbs

Overview

Rack middleware. Non-destructive: publishes redacted copies at env.

Constant Summary collapse

QUERY_STRING =

Returns:

  • (String)
"QUERY_STRING"
ENV_QUERY =

Returns:

  • (String)
"scrubber.query_string"
ENV_PARAMS =

Returns:

  • (String)
"scrubber.params"
ENV_INSTANCE =

Returns:

  • (String)
"scrubber.instance"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, scrubber: nil, scrub_exceptions: true, **options) ⇒ Middleware

Returns a new instance of Middleware.

Parameters:

  • app (#call)

    the next Rack app.

  • scrubber (Scrubber::Instance) (defaults to: nil)

    a prebuilt engine, if you have one.

  • scrub_exceptions (Boolean) (defaults to: true)

    redact exception messages (default true).

  • options (Hash)

    otherwise, options for Scrubber.new.



38
39
40
41
42
# File 'lib/scrubber/middleware.rb', line 38

def initialize(app, scrubber: nil, scrub_exceptions: true, **options)
  @app = app
  @scrubber = scrubber || Scrubber.new(**options)
  @scrub_exceptions = scrub_exceptions
end

Instance Attribute Details

#scrubberInstance (readonly)

Returns the value of attribute scrubber.

Returns:



32
33
34
# File 'lib/scrubber/middleware.rb', line 32

def scrubber
  @scrubber
end

Instance Method Details

#call(env) ⇒ Object

Parameters:

  • env (Hash[String, untyped])

Returns:

  • (Object)


44
45
46
47
48
49
50
51
# File 'lib/scrubber/middleware.rb', line 44

def call(env)
  annotate(env)
  @app.call(env)
rescue StandardError => e
  raise unless @scrub_exceptions

  raise redacted(e)
end