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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afb46d689c5154eb693c9119bfc886143c3d216f
4
- data.tar.gz: e996f74dff07b5b3617827602fc18fb58b47dc88
3
+ metadata.gz: 37acbffe010f5a7cc7232c7ed5de1ae2ed9b5350
4
+ data.tar.gz: 10aaddbd80122deab1b4b5bb6eae0b2344cd66e2
5
5
  SHA512:
6
- metadata.gz: f27b9ce272094f7bc872db9c17514157b0fd5cf62df676fb533a9e319b46e89e5e52303efb2b66c041216b4630f7c796eca52698307aa3919b63d91d8fffcc91
7
- data.tar.gz: 750c07d6f8797e415d6877063a7357a60d425a1dbd4078681acedc4e962adbde0df1e3dab0450e80c023cefe3234c025467d27eb988cc91d19f9c3615e4af878
6
+ metadata.gz: 3afcb545d0eb893599108882bb136adbe89948fe6130c779898a5155729d54f5223ae9429353fd979e17170ec8f85aaab1ebd4fcc6b6ec652401ce02a417ed50
7
+ data.tar.gz: 9f322b1f40ab79346774fb582c389c714417d773014e2507da01c0ece161dce048668ccfaa1d6ff952eaa31f95d2849bb0e8576181f977089b0a3a74103caca4
@@ -1,6 +1,6 @@
1
1
  class TransparentProxy
2
2
 
3
- VERSION = '0.0.2'
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
- __getobj__.inspect
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) | __getobj__.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) || __getobj__.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
- __setobj__ object
36
+ def initialize(object=nil, &block)
37
+ @target = object
38
+ @target_block = block
38
39
  end
39
40
 
40
- def __getobj__
41
- @object
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
- __getobj__.send(method, *args, &block)
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
- it 'Transparent' do
6
- proxy = TransparentProxy.new 1
5
+ samples = {
6
+ 'Transparent' => TransparentProxy.new(2),
7
+ 'Lazy' => TransparentProxy.new { 1 + 1 }
8
+ }
7
9
 
8
- proxy.must_equal 1
9
- (proxy + 1).must_equal 2
10
- proxy.class.must_equal Fixnum
11
- proxy.inspect.must_equal 1.inspect
12
- proxy.methods.must_equal proxy.proxy_methods | 1.methods
13
- proxy.respond_to?(:+).must_equal true
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.2
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: 2014-04-29 00:00:00.000000000 Z
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler