multiplex 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,11 +1,14 @@
1
1
  Multiplex
2
2
  =========
3
3
 
4
- Multiplex lets you bind Net::HTTP requests to non-default local IP
5
- addresses. If you are craving cURL's interface option, this is what
4
+ Multiplex gently monkey-patches TCPSocket to bind a Net::HTTP request to a
5
+ non-default local IP address.
6
+
7
+ If you are craving cURL's `--interface` option to fire HTTP requests over
8
+ multiple local IPs and are looking for a native Ruby solution, this is what
6
9
  you need.
7
10
 
8
- [gatling gun](http://upload.wikimedia.org/wikipedia/commons/6/6c/Gatling_gun.jpg)
11
+ ![tellier](http://totallywiredradio.files.wordpress.com/2009/09/tellier.jpg?w=450&h=450)
9
12
 
10
13
  Usage
11
14
  -----
@@ -1,14 +1,19 @@
1
1
  require 'net/http'
2
2
 
3
+ # Multiplex gently monkey-patches TCPSocket to bind a Net::HTTP request to a
4
+ # non-default local IP address.
5
+ #
6
+ # If you are craving cURL's `interface` option, this is what you need.
3
7
  module Multiplex
4
- def bind(local_ip)
5
- TCPSocket.instance_eval do
6
- (class << self; self; end).instance_eval do
7
- alias_method :original_open, :open
8
8
 
9
- define_method(:open) do |conn_address, conn_port|
10
- original_open(conn_address, conn_port, local_ip)
11
- end
9
+ # Binds to a local IP address.
10
+ #
11
+ # If given a block, unbinds at the end of the block.
12
+ def bind(local_ip)
13
+ (class << TCPSocket; self; end).instance_eval do
14
+ alias_method :original_open, :open
15
+ define_method(:open) do |conn_address, conn_port|
16
+ original_open(conn_address, conn_port, local_ip)
12
17
  end
13
18
  end
14
19
 
@@ -21,18 +26,13 @@ module Multiplex
21
26
  end
22
27
  end
23
28
 
29
+ # Unbinds from the local IP address specified in earlier call to `bind`.
24
30
  def unbind
25
- TCPSocket.instance_eval do
26
- (class << self; self; end).instance_eval do
27
- alias_method :open, :original_open
28
- remove_method :original_open
29
- end
31
+ (class << TCPSocket; self; end).instance_eval do
32
+ alias_method :open, :original_open
33
+ remove_method :original_open
30
34
  end
31
35
  end
32
36
  end
33
37
 
34
- module Net
35
- class HTTP
36
- extend Multiplex
37
- end
38
- end
38
+ class Net::HTTP; extend Multiplex; end
@@ -1,3 +1,3 @@
1
1
  module Multiplex
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
@@ -53,4 +53,9 @@ class TestMultiplex < Test::Unit::TestCase
53
53
  TCPSocket.original_open
54
54
  end
55
55
  end
56
+
57
+ def test_bind_nil
58
+ Net::HTTP.bind(nil)
59
+ assert_equal @@old_ip, find_ip
60
+ end
56
61
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: multiplex
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paper Cavalier
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-11 00:00:00 +00:00
13
+ date: 2011-03-18 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies: []
16
16