Class: Rack::CopyMachine
- Inherits:
-
Object
- Object
- Rack::CopyMachine
- Defined in:
- lib/rack/copy_machine/asset_server.rb,
lib/rack/copy_machine.rb
Defined Under Namespace
Classes: AssetServer
Instance Method Summary collapse
- #_call(env) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ CopyMachine
constructor
A new instance of CopyMachine.
- #inject_copy_notification ⇒ Object
- #modify_body ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ CopyMachine
Returns a new instance of CopyMachine.
4 5 6 |
# File 'lib/rack/copy_machine.rb', line 4 def initialize(app, = {}) @app = asset_server(app) end |
Instance Method Details
#_call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/rack/copy_machine.rb', line 10 def _call(env) @request = Rack::Request.new(env) status, headers, body = @app.call(env) @response = Rack::Response.new(body, status, headers) inject_copy_notification @response.finish end |
#call(env) ⇒ Object
8 |
# File 'lib/rack/copy_machine.rb', line 8 def call(env); dup._call(env); end |
#inject_copy_notification ⇒ Object
20 21 22 23 24 |
# File 'lib/rack/copy_machine.rb', line 20 def inject_copy_notification modify_body do ::ERB.new(::File.read(::File.dirname(__FILE__) + "/views/notifications.html.erb")).result end end |
#modify_body ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/rack/copy_machine.rb', line 26 def modify_body full_body = @response.body.join full_body.sub! /<\/head>/, "</head>\n" + yield @response["Content-Length"] = full_body.size.to_s @response.body = [full_body] end |