Class: Pushify::Rack
- Inherits:
-
Object
- Object
- Pushify::Rack
- Defined in:
- lib/pushify/rack.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app) ⇒ Rack
Returns a new instance of Rack.
3 4 5 |
# File 'lib/pushify/rack.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 18 19 20 21 22 23 24 |
# File 'lib/pushify/rack.rb', line 7 def call(env) path = env["REQUEST_URI"] if (Pushify::Rails::Assets.includes?(path)) Pushify::Rails::Assets.response(path) else status, headers, response = @app.call(env) is_html = !response.is_a?(Array) && (headers["Content-Type"].nil? || headers["Content-Type"].include?("text/html")) if (is_html && response.body.match(/<\/body>/)) pushify_src = Pushify.javascript_src response.body = response.body.gsub(/(<\/body>)/, "#{pushify_src}</body>") headers["Content-Length"] = (response.body.size).to_s end [status, headers, response] end end |