Class: Rack::Insight::EnableButton
- Inherits:
-
Struct
- Object
- Struct
- Rack::Insight::EnableButton
show all
- Includes:
- Render
- Defined in:
- lib/rack/insight/enable-button.rb
Constant Summary
collapse
- CONTENT_TYPE_REGEX =
/text\/(html|plain)|application\/xhtml\+xml/
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Render
#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params
Methods included from Logging
logger, verbose, verbosity
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app
2
3
4
|
# File 'lib/rack/insight/enable-button.rb', line 2
def app
@app
end
|
#insight ⇒ Object
Returns the value of attribute insight
2
3
4
|
# File 'lib/rack/insight/enable-button.rb', line 2
def insight
@insight
end
|
Instance Method Details
#call(env) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/rack/insight/enable-button.rb', line 7
def call(env)
status, , response = app.call(env)
if okay_to_modify?(env, )
body = response.inject("") do |memo, part|
memo << part
memo
end
index = body.rindex("</body>")
if index
body.insert(index, render)
["Content-Length"] = body.bytesize.to_s
response = [body]
end
end
[status, , response]
end
|
#match_path_filters?(path_filters, path) ⇒ Boolean
31
32
33
|
# File 'lib/rack/insight/enable-button.rb', line 31
def match_path_filters?(path_filters, path)
to_regex(path_filters).find { |filter| path =~ filter }
end
|
#okay_to_modify?(env, headers) ⇒ Boolean
26
27
28
29
|
# File 'lib/rack/insight/enable-button.rb', line 26
def okay_to_modify?(env, )
return false unless ["Content-Type"] =~ CONTENT_TYPE_REGEX
return !match_path_filters?(env["rack-insight.path_filters"], env["REQUEST_PATH"])
end
|
#render ⇒ Object
39
40
41
|
# File 'lib/rack/insight/enable-button.rb', line 39
def render
render_template("enable-button")
end
|
#to_regex(filters) ⇒ Object
35
36
37
|
# File 'lib/rack/insight/enable-button.rb', line 35
def to_regex(filters)
(filters || []).map { |str| %r(^#{str}) }
end
|