raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Ben Somers <somers.ben@gmail.com>
To: raindrops@librelist.org
Subject: [PATCH] Add method_missing to Raindrops::Middleware::Proxy
Date: Thu, 17 May 2012 18:46:58 -0700	[thread overview]
Message-ID: <CAO1NZApFZa_SQk12ZZOo1ZTukfnxMsZ=-NG7aZ8f1v8xL6quyA@mail.gmail.com> (raw)
In-Reply-To: <CAO1NZApFZa_SQk12ZZOo1ZTukfnxMsZ=-NG7aZ8f1v8xL6quyA@mail.gmail.com>

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
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)
+  # Rack::BodyProxy objects use +method_missing+ to delegate methods
+  # to their bodies
+  def method_missing(*args, &block)
+    @body.send(*args, &block)
+  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

       reply	other threads:[~2012-05-18  1:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-18  1:46 Ben Somers [this message]
2012-05-18  2:35 ` [PATCH] Add method_missing to Raindrops::Middleware::Proxy Eric Wong
2012-05-18  3:56   ` Ben Somers
2012-05-18  4:27     ` Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: http://yhbt.net/raindrops/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAO1NZApFZa_SQk12ZZOo1ZTukfnxMsZ=-NG7aZ8f1v8xL6quyA@mail.gmail.com' \
    --to=somers.ben@gmail.com \
    --cc=raindrops@librelist.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).