Class: Brut::FrontEnd::Middlewares::AnnotateBrutOwnedPaths

Inherits:
Brut::FrontEnd::Middleware show all
Defined in:
lib/brut/front_end/middlewares/annotate_brut_owned_paths.rb

Overview

Annotates any path that is owned by Brut as such. Alleviates downstream code from having to include the actual path determination Brut uses. After this middleware has run, env["brut.owned_path"] will return true if the path represents one that Brut is managing.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ AnnotateBrutOwnedPaths

Returns a new instance of AnnotateBrutOwnedPaths.



5
6
7
# File 'lib/brut/front_end/middlewares/annotate_brut_owned_paths.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/brut/front_end/middlewares/annotate_brut_owned_paths.rb', line 8

def call(env)
  if env["PATH_INFO"] =~ /^\/__brut\//
    Brut.container.instrumentation.add_attributes(prefix: "brut", owned_path: true)
    env["brut.owned_path"] = true
  end
  @app.call(env)
end