From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS6939 64.71.128.0/18 X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Ben Somers Newsgroups: gmane.comp.lang.ruby.raindrops.general Subject: [PATCH] Add method_missing to Raindrops::Middleware::Proxy Date: Thu, 17 May 2012 18:46:58 -0700 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1337305677 21195 80.91.229.3 (18 May 2012 01:47:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 18 May 2012 01:47:57 +0000 (UTC) To: raindrops@librelist.org Original-X-From: raindrops@librelist.org Fri May 18 03:47:56 2012 Return-path: Envelope-to: gclrrg-raindrops@m.gmane.org In-Reply-To: List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: raindrops@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.raindrops.general:68 Archived-At: Received: from zedshaw.xen.prgmr.com ([64.71.167.205]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SVCIN-0003Iz-8v for gclrrg-raindrops@m.gmane.org; Fri, 18 May 2012 03:47:55 +0200 Received: from zedshaw.xen.prgmr.com (localhost [IPv6:::1]) by zedshaw.xen.prgmr.com (Postfix) with ESMTP id 2A5E521DBA4 for ; Fri, 18 May 2012 01:55:28 +0000 (UTC) This enables it to behave more like a Rack BodyProxy would, delegating methods to its body object when it does not implement them itself. (Also includes a minor grammar fix to a comment.) --- Here you go! Hopefully this is a patch format you appreciate? Guidelines are a little less clear than on unicorn :p. lib/raindrops/middleware/proxy.rb | 11 +++++++++-- test/test_middleware.rb | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/raindrops/middleware/proxy.rb b/lib/raindrops/middleware/proxy.rb index 53e14b5..51be3eb 100644 --- a/lib/raindrops/middleware/proxy.rb +++ b/lib/raindrops/middleware/proxy.rb @@ -1,7 +1,7 @@ # -*- encoding: binary -*- # :stopdoc: -# This class is by Raindrops::Middleware to proxy application response -# bodies. There should be no need to use it directly. +# This class is used by Raindrops::Middleware to proxy application +# response bodies. There should be no need to use it directly. class Raindrops::Middleware::Proxy def initialize(body, stats) @body, @stats = body, stats @@ -31,4 +31,11 @@ class Raindrops::Middleware::Proxy m = m.to_sym :close == m || @body.respond_to?(m) end + + # Rack::BodyProxy objects use +method_missing+ to delegate methods + # to their bodies + def method_missing(*args, &block) + @body.send(*args, &block) + end + end diff --git a/test/test_middleware.rb b/test/test_middleware.rb index eedf04a..56ce346 100644 --- a/test/test_middleware.rb +++ b/test/test_middleware.rb @@ -120,5 +120,9 @@ class TestMiddleware < Test::Unit::TestCase def orig_body.to_path; "/dev/null"; end assert body.respond_to?(:to_path) assert_equal "/dev/null", body.to_path + + def orig_body.body; "this is a body"; end + assert body.respond_to?(:body) + assert_equal "this is a body", body.body end end -- 1.7.7.4