Class: DevToolbar::Middleware
- Inherits:
-
Object
- Object
- DevToolbar::Middleware
- Defined in:
- lib/dev_toolbar/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #error_message ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
- #pass_through? ⇒ Boolean
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
3 4 5 |
# File 'lib/dev_toolbar/middleware.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/dev_toolbar/middleware.rb', line 7 def call(env) request = Rack::Request.new(env) @ip = request.ip @app.call(env) rescue Exception => ex if pass_through? @app.call(env) else [200, {"Content-Type" => "text/html"}, []] end end |
#error_message ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dev_toolbar/middleware.rb', line 29 def " <h1>Uh oh! You've got an error in your code.</h1>\n\n <h2>To get a more helpful error page, please run this command at a terminal prompt:</h2>\n\n <pre style=\"font-size: 4em;\"><code>bin/whitelist \#{@ip}</code></pre>\n\n <h2>and then restart your server.</h2>\n HTML\nend\n" |
#pass_through? ⇒ Boolean
19 20 21 22 23 24 25 26 27 |
# File 'lib/dev_toolbar/middleware.rb', line 19 def pass_through? path = Rails.root.join('whitelist.yml') if File.exist?(path) whitelisted_ips = YAML.load_file(path) whitelisted_ips.include?(@ip) else true end end |