transparent_proxy 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/transparent_proxy.rb +10 -13
- data/spec/transparent_proxy_spec.rb +13 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37acbffe010f5a7cc7232c7ed5de1ae2ed9b5350
|
4
|
+
data.tar.gz: 10aaddbd80122deab1b4b5bb6eae0b2344cd66e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3afcb545d0eb893599108882bb136adbe89948fe6130c779898a5155729d54f5223ae9429353fd979e17170ec8f85aaab1ebd4fcc6b6ec652401ce02a417ed50
|
7
|
+
data.tar.gz: 9f322b1f40ab79346774fb582c389c714417d773014e2507da01c0ece161dce048668ccfaa1d6ff952eaa31f95d2849bb0e8576181f977089b0a3a74103caca4
|
data/lib/transparent_proxy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class TransparentProxy
|
2
2
|
|
3
|
-
VERSION = '0.0.
|
3
|
+
VERSION = '0.0.3'
|
4
4
|
|
5
5
|
proxy_methods = [:class, :methods, :respond_to?]
|
6
6
|
|
@@ -12,7 +12,7 @@ class TransparentProxy
|
|
12
12
|
each { |m| undef_method m }
|
13
13
|
|
14
14
|
def inspect
|
15
|
-
|
15
|
+
__target__.inspect
|
16
16
|
end
|
17
17
|
|
18
18
|
def proxy_inspect
|
@@ -20,11 +20,11 @@ class TransparentProxy
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def methods(*args)
|
23
|
-
proxy_methods(*args) |
|
23
|
+
proxy_methods(*args) | __target__.methods(*args)
|
24
24
|
end
|
25
25
|
|
26
26
|
def respond_to?(*args)
|
27
|
-
proxy_respond_to?(*args) ||
|
27
|
+
proxy_respond_to?(*args) || __target__.respond_to?(*args)
|
28
28
|
end
|
29
29
|
|
30
30
|
def proxy?
|
@@ -33,20 +33,17 @@ class TransparentProxy
|
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
-
def initialize(object)
|
37
|
-
|
36
|
+
def initialize(object=nil, &block)
|
37
|
+
@target = object
|
38
|
+
@target_block = block
|
38
39
|
end
|
39
40
|
|
40
|
-
def
|
41
|
-
@
|
42
|
-
end
|
43
|
-
|
44
|
-
def __setobj__(object)
|
45
|
-
@object = object
|
41
|
+
def __target__
|
42
|
+
@target ||= @target_block.call
|
46
43
|
end
|
47
44
|
|
48
45
|
def method_missing(method, *args, &block)
|
49
|
-
|
46
|
+
__target__.send(method, *args, &block)
|
50
47
|
end
|
51
48
|
|
52
49
|
end
|
@@ -2,15 +2,20 @@ require 'minitest_helper'
|
|
2
2
|
|
3
3
|
describe TransparentProxy do
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
samples = {
|
6
|
+
'Transparent' => TransparentProxy.new(2),
|
7
|
+
'Lazy' => TransparentProxy.new { 1 + 1 }
|
8
|
+
}
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
samples.each do |label, proxy|
|
11
|
+
it label do
|
12
|
+
proxy.must_equal 2
|
13
|
+
(proxy + 1).must_equal 3
|
14
|
+
proxy.class.must_equal Fixnum
|
15
|
+
proxy.inspect.must_equal 2.inspect
|
16
|
+
proxy.methods.must_equal proxy.proxy_methods | 2.methods
|
17
|
+
proxy.respond_to?(:+).must_equal true
|
18
|
+
end
|
14
19
|
end
|
15
20
|
|
16
21
|
it 'Proxy methods' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transparent_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|