~ubuntu-branches/ubuntu/raring/ruby-actionpack-3.2/raring

« back to all changes in this revision

Viewing changes to lib/action_dispatch/middleware/body_proxy.rb

  • Committer: Package Import Robot
  • Author(s): Ondřej Surý
  • Date: 2012-04-25 09:14:01 UTC
  • Revision ID: package-import@ubuntu.com-20120425091401-3nkf83btcemhjquo
Tags: upstream-3.2.3
Import upstream version 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Keep this file meanwhile https://github.com/rack/rack/pull/313 is not released
 
2
module ActionDispatch
 
3
  class BodyProxy
 
4
    def initialize(body, &block)
 
5
      @body, @block, @closed = body, block, false
 
6
    end
 
7
 
 
8
    def respond_to?(*args)
 
9
      super or @body.respond_to?(*args)
 
10
    end
 
11
 
 
12
    def close
 
13
      return if @closed
 
14
      @closed = true
 
15
      begin
 
16
        @body.close if @body.respond_to? :close
 
17
      ensure
 
18
        @block.call
 
19
      end
 
20
    end
 
21
 
 
22
    def closed?
 
23
      @closed
 
24
    end
 
25
 
 
26
    def method_missing(*args, &block)
 
27
      @body.__send__(*args, &block)
 
28
    end
 
29
  end
 
30
end