Class: Bushido::Middleware
- Inherits:
-
Object
- Object
- Bushido::Middleware
- Includes:
- Rack::Utils
- Defined in:
- lib/bushido/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, opts = {}) ⇒ Middleware
Returns a new instance of Middleware.
7 8 9 |
# File 'lib/bushido/middleware.rb', line 7 def initialize(app, opts = {}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bushido/middleware.rb', line 11 def call(env) if Bushido::Platform.on_bushido? and Bushido::Bar.(env) status, headers, response = @app.call(env) content = "" response.each { |part| content += part } # "claiming" bar + stats ? content.gsub!(/<\/body>/i, " <script type=\"text/javascript\">\n var _bushido_app = '\#{Bushido::Platform.name}';\n var _bushido_claimed = \#{Bushido::Platform.claimed?.to_s};\n var _bushido_metrics_token = '\#{Bushido::Platform.metrics_token}';\n (function() {\n var bushido = document.createElement('script'); bushido.type = 'text/javascript'; bushido.async = true;\n bushido.src = '\#{Bushido::Platform.bushido_js_source}?t=\#{::Bushido::VERSION.gsub('.', '')}';\n var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(bushido, s);\n })();\n </script> \n </body>\n STR\n )\n\n headers['content-length'] = bytesize(content).to_s\n [status, headers, [content]]\n else\n @app.call(env)\n end\nend\n" |