bzproxies 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/bzproxies.gemspec +1 -1
- data/lib/bzproxies/basic_object.rb +4 -4
- data/lib/bzproxies/owner.rb +4 -1
- data/lib/bzproxies/version.rb +1 -1
- data/spec/accessors_spec.rb +2 -0
- data/spec/base_spec.rb +35 -26
- metadata +61 -34
data/README.md
CHANGED
@@ -30,7 +30,7 @@ You can use some objects that mimics objects covered by proxies:
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
<i>TODO: create global function
|
33
|
+
<i>TODO: create global function creating stub for concrete proxy (as same one in Delegate class).</i>
|
34
34
|
|
35
35
|
Than you may use proxy_accessor to specify attribute that will cover some given values with proxy:
|
36
36
|
|
data/bzproxies.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = Base64.decode64("Ym9tYmF6b29rQGdtYWlsLmNvbQ==\n")
|
11
11
|
s.homepage = "http://github.com/bombazook/bzproxies"
|
12
12
|
s.summary = "collection of reusable proxies and accessors"
|
13
|
-
s.description = s.summary + "etc."
|
13
|
+
s.description = s.summary + " and etc."
|
14
14
|
|
15
15
|
s.rubyforge_project = "bzproxies"
|
16
16
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
class BasicObject
|
2
|
+
instance_methods.each do |m|
|
3
|
+
undef_method m unless m =~ /(^__|^send$|^object_id$|^equal\?$|^instance_eval$|^instance_exec$)/
|
4
4
|
end
|
5
|
-
end
|
5
|
+
end unless defined? BasicObject
|
data/lib/bzproxies/owner.rb
CHANGED
@@ -18,7 +18,7 @@ module Proxies
|
|
18
18
|
proxies.flatten!
|
19
19
|
proxies.compact!
|
20
20
|
proxy = proxies.shift || Proxies::Base
|
21
|
-
unless proxy.
|
21
|
+
unless proxy.method_defined? :proxy?
|
22
22
|
raise ArgumentError, "Expected proxy, given #{proxy.inspect} #{proxy.class}"
|
23
23
|
end
|
24
24
|
args.each do |name|
|
@@ -26,11 +26,13 @@ module Proxies
|
|
26
26
|
raise ArgumentError, "Expected String or Symbol, given #{name.inspect} #{name.class}"
|
27
27
|
end
|
28
28
|
define_method("#{name}=") do |v|
|
29
|
+
val = nil
|
29
30
|
if v.respond_to? :stub?
|
30
31
|
val = v
|
31
32
|
else
|
32
33
|
val = proxy.send :new, v, :proxies => proxies
|
33
34
|
end
|
35
|
+
#instance_exec(val){|x| instance_eval("@#{name} = x")}
|
34
36
|
instance_eval("@#{name} = val")
|
35
37
|
end
|
36
38
|
end
|
@@ -42,5 +44,6 @@ module Proxies
|
|
42
44
|
end
|
43
45
|
|
44
46
|
end
|
47
|
+
|
45
48
|
end
|
46
49
|
end
|
data/lib/bzproxies/version.rb
CHANGED
data/spec/accessors_spec.rb
CHANGED
@@ -37,8 +37,10 @@ describe Proxies::Owner::Accessors do
|
|
37
37
|
owner = Ex2.new
|
38
38
|
owner.test = a
|
39
39
|
owner.test.equal?(a).should be_true
|
40
|
+
owner.test.object_id.should be_equal(a.object_id)
|
40
41
|
owner.test = b
|
41
42
|
owner.test.equal?(b).should be_true
|
43
|
+
owner.test.object_id.should be_equal(b.object_id)
|
42
44
|
end
|
43
45
|
|
44
46
|
it "should raise an exception while non-proxy class given" do
|
data/spec/base_spec.rb
CHANGED
@@ -28,11 +28,6 @@ describe Proxies::Base do
|
|
28
28
|
proxy.target.should be_equal(a)
|
29
29
|
a.should be_equal(inherited.target)
|
30
30
|
a.should be_equal(proxy.target)
|
31
|
-
|
32
|
-
(inherited.equal? a).should be_false
|
33
|
-
(proxy.equal? a).should be_false
|
34
|
-
a.should_not be_equal(inherited)
|
35
|
-
a.should_not be_equal(proxy)
|
36
31
|
end
|
37
32
|
|
38
33
|
it "return proxy-contained object of 2-level proxy" do
|
@@ -58,28 +53,42 @@ describe Proxies::Base do
|
|
58
53
|
|
59
54
|
|
60
55
|
it "should be eql and == for same and equal object proxies" do
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
56
|
+
["string", 1, false, nil].each do |val|
|
57
|
+
a = val
|
58
|
+
test1 = Proxy.new a
|
59
|
+
test2 = Proxy.new a
|
60
|
+
test3 = Proxy.new val
|
61
|
+
|
62
|
+
(a == test1).should be_true
|
63
|
+
(a == test3).should be_true
|
64
|
+
(test1 == a).should be_true
|
65
|
+
(test3 == a).should be_true
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
(test1.eql? test2).should be_true
|
80
|
-
(test2.eql? test1).should be_true
|
81
|
-
(test1.eql? test3).should be_true
|
82
|
-
(test3.eql? test1).should be_true
|
67
|
+
a.should_not be_eql test1
|
68
|
+
(test1.eql? a).should be_false
|
69
|
+
|
70
|
+
(test1 == test2).should be_true
|
71
|
+
(test2 == test1).should be_true
|
72
|
+
(test1 == test3).should be_true
|
73
|
+
(test3 == test1).should be_true
|
74
|
+
|
75
|
+
(test1.eql? test2).should be_true
|
76
|
+
(test2.eql? test1).should be_true
|
77
|
+
(test1.eql? test3).should be_true
|
78
|
+
(test3.eql? test1).should be_true
|
79
|
+
end
|
83
80
|
end
|
84
81
|
|
82
|
+
it "shouldn't be equal with non-proxy object" do
|
83
|
+
a = "source"
|
84
|
+
inherited = Inherited.new(a)
|
85
|
+
proxy = Proxy.new(a)
|
86
|
+
(inherited.equal? a).should be_false
|
87
|
+
(proxy.equal? a).should be_false
|
88
|
+
(a.equal? inherited).should be_false
|
89
|
+
(a.equal? proxy).should be_false
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
85
94
|
end
|
metadata
CHANGED
@@ -1,44 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: bzproxies
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Bombazook
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2011-10-27 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: bundler
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
25
|
+
requirements:
|
19
26
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 15
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
version: "1.0"
|
22
33
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
26
36
|
name: rspec
|
27
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
|
-
requirements:
|
40
|
+
requirements:
|
30
41
|
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 15
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- 6
|
47
|
+
version: "2.6"
|
33
48
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
description: collection of reusable proxies and accessorsetc.
|
49
|
+
version_requirements: *id002
|
50
|
+
description: collection of reusable proxies and accessors and etc.
|
37
51
|
email: bombazook@gmail.com
|
38
52
|
executables: []
|
53
|
+
|
39
54
|
extensions: []
|
55
|
+
|
40
56
|
extra_rdoc_files: []
|
41
|
-
|
57
|
+
|
58
|
+
files:
|
42
59
|
- .gitignore
|
43
60
|
- .rspec
|
44
61
|
- Gemfile
|
@@ -65,26 +82,36 @@ files:
|
|
65
82
|
- spec/spec_helper.rb
|
66
83
|
homepage: http://github.com/bombazook/bzproxies
|
67
84
|
licenses: []
|
85
|
+
|
68
86
|
post_install_message:
|
69
87
|
rdoc_options: []
|
70
|
-
|
88
|
+
|
89
|
+
require_paths:
|
71
90
|
- lib
|
72
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
92
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
101
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
84
109
|
requirements: []
|
110
|
+
|
85
111
|
rubyforge_project: bzproxies
|
86
|
-
rubygems_version: 1.8.
|
112
|
+
rubygems_version: 1.8.10
|
87
113
|
signing_key:
|
88
114
|
specification_version: 3
|
89
115
|
summary: collection of reusable proxies and accessors
|
90
116
|
test_files: []
|
117
|
+
|