object-proxy 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -3
- data/Gemfile.lock +11 -9
- data/README.md +80 -11
- data/Rakefile +4 -12
- data/VERSION +1 -1
- data/lib/object-proxy.rb +182 -18
- data/object-proxy.gemspec +17 -17
- data/test +40 -1
- metadata +56 -58
data/Gemfile
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
|
-
gem "hash-utils", ">= 0.12.
|
4
|
+
gem "hash-utils", ">= 0.12.1"
|
5
5
|
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
group :development do
|
9
|
-
gem "bundler", "
|
10
|
-
gem "jeweler", "
|
9
|
+
gem "bundler", ">= 1.0.0"
|
10
|
+
gem "jeweler", ">= 1.5.2"
|
11
11
|
gem "riot", ">= 0.12.1"
|
12
12
|
end
|
data/Gemfile.lock
CHANGED
@@ -2,21 +2,23 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
git (1.2.5)
|
5
|
-
hash-utils (
|
6
|
-
|
7
|
-
|
5
|
+
hash-utils (1.1.0)
|
6
|
+
ruby-version
|
7
|
+
jeweler (1.6.4)
|
8
|
+
bundler (~> 1.0)
|
8
9
|
git (>= 1.2.5)
|
9
10
|
rake
|
10
|
-
rake (0.
|
11
|
-
riot (0.12.
|
11
|
+
rake (0.9.2)
|
12
|
+
riot (0.12.5)
|
12
13
|
rr
|
13
|
-
rr (1.0.
|
14
|
+
rr (1.0.4)
|
15
|
+
ruby-version (0.3.1)
|
14
16
|
|
15
17
|
PLATFORMS
|
16
18
|
ruby
|
17
19
|
|
18
20
|
DEPENDENCIES
|
19
|
-
bundler (
|
20
|
-
hash-utils (>= 0.12.
|
21
|
-
jeweler (
|
21
|
+
bundler (>= 1.0.0)
|
22
|
+
hash-utils (>= 0.12.1)
|
23
|
+
jeweler (>= 1.5.2)
|
22
24
|
riot (>= 0.12.1)
|
data/README.md
CHANGED
@@ -2,22 +2,22 @@ Object Proxy
|
|
2
2
|
============
|
3
3
|
|
4
4
|
**object-proxy** provides proxy objects intended for intercepting calls
|
5
|
-
to instance methods.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
to instance methods. It's aimed as tool for instant adapting the complex
|
6
|
+
objects without complete deriving and extending whole classes in cases,
|
7
|
+
where isn't possible to derive them as homogenic functional units or
|
8
|
+
where it's simply impractical to derive them. Provides four base
|
9
|
+
proxy types.
|
10
|
+
|
11
|
+
### Standard Proxy
|
12
|
+
Works as intermediate layer between caller and called. Allows to invoke
|
13
|
+
an handler both before method call and adjust its arguments and after
|
14
|
+
call and post-proccess result.
|
12
15
|
|
13
16
|
See some slightly stupid example:
|
14
17
|
|
15
18
|
require "object-proxy"
|
16
19
|
|
17
|
-
|
18
|
-
# OP[...] is shortcut, it creates the proxy object instance
|
19
|
-
|
20
|
-
s = OP["1 2 3 4"]
|
20
|
+
s = OP::proxy("1 2 3 4")
|
21
21
|
s.before_split do |args|
|
22
22
|
args = [" "]
|
23
23
|
end
|
@@ -30,6 +30,75 @@ See some slightly stupid example:
|
|
30
30
|
p out
|
31
31
|
|
32
32
|
Will print out `[2, 3, 4, 5]`.
|
33
|
+
|
34
|
+
### Fake Proxy
|
35
|
+
Simply fakes interface of an class, but with empty methods. Necessary
|
36
|
+
methods can be individually overwritten by custom callbacks. It's
|
37
|
+
equivalent to manual deriving class and reseting all its methods
|
38
|
+
to nothing.
|
39
|
+
|
40
|
+
See some slightly stupid example:
|
41
|
+
|
42
|
+
pr = OP::fake(String, [:kind_of?]) do # we will use #kind_of? below,
|
43
|
+
# so we need say, we don't want to reset it
|
44
|
+
|
45
|
+
define_method :to_s do # let's say, '#to_s' will return
|
46
|
+
"alfa beta" # fixed value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
pr.to_s == "alfa beta" # '#to_s' returns fixed value
|
51
|
+
pr.inspect.nil? # '#inspect' and all others are reset
|
52
|
+
# and return nil
|
53
|
+
|
54
|
+
pr.kind_of? String # but object still seems to be String :-)
|
55
|
+
|
56
|
+
### Tracking Proxy
|
57
|
+
It's similar to *standard proxy*, but points all callbacks to single
|
58
|
+
callback set (single for before call callbacks and single for after call
|
59
|
+
callbacks). Also doesn't allow to modify arguments and postprocess
|
60
|
+
results.
|
61
|
+
|
62
|
+
See some slightly stupid example:
|
63
|
+
|
64
|
+
calls = [ ]
|
65
|
+
s = OP::track("a,b,c,d")
|
66
|
+
|
67
|
+
s.before_call do |name| # sets 'before_call' handler
|
68
|
+
# track call names to array
|
69
|
+
calls << name
|
70
|
+
end
|
71
|
+
|
72
|
+
s << ",1,2,3"
|
73
|
+
s.gsub!(",", " ")
|
74
|
+
s.split(" ")
|
75
|
+
|
76
|
+
p calls
|
77
|
+
|
78
|
+
Will print out `[:<<, :gsub!, :split]`.
|
79
|
+
|
80
|
+
### Catching Proxy
|
81
|
+
Catches all method calls and forwards them to the `#method_call` handler which
|
82
|
+
calls wrapped object by default, but can be overriden, so calls can be
|
83
|
+
fully controlled.
|
84
|
+
|
85
|
+
See some slightly stupid example:
|
86
|
+
|
87
|
+
s = OP::catch("foo")
|
88
|
+
|
89
|
+
s.method_call do |name, args, block|
|
90
|
+
if name == :to_s
|
91
|
+
s.wrapped.send(name, *args, &block)
|
92
|
+
else
|
93
|
+
:nothing
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
p s.replace("beta") # will print ":nothing" out
|
98
|
+
s.to_s # will print "foo" out
|
99
|
+
|
100
|
+
But object still seems to be `String`.
|
101
|
+
|
33
102
|
|
34
103
|
Contributing
|
35
104
|
------------
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'rubygems'
|
3
3
|
require 'bundler'
|
4
|
+
|
4
5
|
begin
|
5
6
|
Bundler.setup(:default, :development)
|
6
7
|
rescue Bundler::BundlerError => e
|
@@ -8,15 +9,16 @@ rescue Bundler::BundlerError => e
|
|
8
9
|
$stderr.puts "Run `bundle install` to install missing gems"
|
9
10
|
exit e.status_code
|
10
11
|
end
|
11
|
-
require 'rake'
|
12
12
|
|
13
|
+
require 'rake'
|
13
14
|
require 'jeweler'
|
15
|
+
|
14
16
|
Jeweler::Tasks.new do |gem|
|
15
17
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
18
|
gem.name = "object-proxy"
|
17
19
|
gem.homepage = "http://github.com/martinkozak/object-proxy"
|
18
20
|
gem.license = "MIT"
|
19
|
-
gem.summary = "Provides proxy objects intended for intercepting calls to instance methods. Works as intermediate layer between caller and called. Allows to invoke an handler both before method call and adjust its arguments and after call and post-proccess result. Aimed as tool for instant adapting the complex objects without complete deriving and extending whole classes in cases, where isn\'t possible to derive them as homogenic functional units or where it's simply impractical to derive them."
|
21
|
+
gem.summary = "Provides collection of four proxy objects intended for intercepting calls to instance methods. Works as intermediate layer between caller and called. Allows to invoke an handler both before method call and adjust its arguments and after call and post-proccess result. Aimed as tool for instant adapting the complex objects without complete deriving and extending whole classes in cases, where isn\'t possible to derive them as homogenic functional units or where it's simply impractical to derive them."
|
20
22
|
gem.email = "martinkozak@martinkozak.net"
|
21
23
|
gem.authors = ["Martin Kozák"]
|
22
24
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
@@ -25,13 +27,3 @@ Jeweler::Tasks.new do |gem|
|
|
25
27
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
28
|
end
|
27
29
|
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
29
|
-
require 'rake/rdoctask'
|
30
|
-
Rake::RDocTask.new do |rdoc|
|
31
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
-
|
33
|
-
rdoc.rdoc_dir = 'rdoc'
|
34
|
-
rdoc.title = "hash-utils #{version}"
|
35
|
-
rdoc.rdoc_files.include('README*')
|
36
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/object-proxy.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
3
|
|
4
|
-
require "hash-utils/symbol"
|
5
|
-
require "hash-utils/object"
|
4
|
+
require "hash-utils/symbol" # >= 0.13.0
|
5
|
+
require "hash-utils/object"
|
6
6
|
|
7
7
|
##
|
8
8
|
# Main ObjectProxy class.
|
@@ -11,23 +11,26 @@ require "hash-utils/object"
|
|
11
11
|
module ObjectProxy
|
12
12
|
|
13
13
|
##
|
14
|
-
# Creates proxy object.
|
14
|
+
# Creates proxy object. "Proxy object" means, it calls handler
|
15
|
+
# if defined before and after each method call.
|
15
16
|
#
|
16
17
|
# @param [Object] object proxied object
|
17
18
|
# @return [Class] anonymous proxy class with before and after
|
18
19
|
# handlers functionality
|
20
|
+
# @since 0.2.0
|
19
21
|
#
|
20
22
|
|
21
|
-
def self.
|
23
|
+
def self.proxy(object)
|
22
24
|
cls = Class::new(object.class)
|
23
25
|
cls.instance_eval do
|
24
26
|
|
25
27
|
# Eviscerates instances methods and replace them by
|
28
|
+
# before and after handlers invoker
|
26
29
|
public_instance_methods.each do |method|
|
27
|
-
if not method.in? [:object_id, :__send__
|
30
|
+
if not method.in? [:object_id, :__send__]
|
28
31
|
define_method method do |*args, &block|
|
29
|
-
before = ("before_"
|
30
|
-
after = ("after_"
|
32
|
+
before = method.prepend("before_")
|
33
|
+
after = method.prepend("after_")
|
31
34
|
|
32
35
|
# before handler
|
33
36
|
if @handlers.include? before
|
@@ -56,7 +59,7 @@ module ObjectProxy
|
|
56
59
|
# Event handlers assigning interceptor
|
57
60
|
define_method :method_missing do |name, *args, &block|
|
58
61
|
if name.start_with? "before_", "after_"
|
59
|
-
self.register_handler(name, block)
|
62
|
+
self.register_handler(name, &block)
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
@@ -70,21 +73,182 @@ module ObjectProxy
|
|
70
73
|
|
71
74
|
return cls::new(object)
|
72
75
|
end
|
73
|
-
end
|
74
|
-
|
75
|
-
##
|
76
|
-
# Shortcut module to [ObjectProxy].
|
77
|
-
#
|
78
76
|
|
79
|
-
module OP
|
80
|
-
|
81
77
|
##
|
82
|
-
# Alias for +ObjectProxy
|
83
|
-
#
|
78
|
+
# Alias for +ObjectProxy::proxy+.
|
79
|
+
#
|
80
|
+
# @return [Class]
|
81
|
+
# @since 0.2.0
|
84
82
|
#
|
85
83
|
|
86
84
|
def self.[](object)
|
87
|
-
|
85
|
+
self::proxy(object)
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# Alias for +ObjectProxy::proxy+.
|
90
|
+
#
|
91
|
+
# @return [Class]
|
92
|
+
# @since 0.1.0
|
93
|
+
#
|
94
|
+
|
95
|
+
def self.create(object)
|
96
|
+
self::proxy(object)
|
88
97
|
end
|
89
98
|
|
99
|
+
##
|
100
|
+
# Creates fake object. "Fake object" means, all methods are replaced
|
101
|
+
# by empty functions or defined bodies.
|
102
|
+
#
|
103
|
+
# Original class public instance functions are aliased to form:
|
104
|
+
# +native_<name of function>+.
|
105
|
+
#
|
106
|
+
# @param [Class] cls class for fake
|
107
|
+
# @param [Proc] block block with definitions of custom methods
|
108
|
+
# which will be run in private context of the faked class
|
109
|
+
# @return [Class] anonymous class faked object
|
110
|
+
# @since 0.2.0
|
111
|
+
#
|
112
|
+
|
113
|
+
def self.fake(cls, omit = [ ], &block)
|
114
|
+
cls = Class::new(cls)
|
115
|
+
cls.instance_eval do
|
116
|
+
omit.concat([:object_id, :__send__])
|
117
|
+
|
118
|
+
# Eviscerates instances methods and replace them by
|
119
|
+
# before and after handlers invoker
|
120
|
+
public_instance_methods.each do |method|
|
121
|
+
if not method.in? omit
|
122
|
+
alias_method method.prepend("native_"), method
|
123
|
+
define_method method do |*args, &block| end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
if not block.nil?
|
129
|
+
cls.instance_eval(&block)
|
130
|
+
end
|
131
|
+
|
132
|
+
return cls
|
133
|
+
end
|
134
|
+
|
135
|
+
##
|
136
|
+
# Creates "tracker object". Works by similar way as standard proxy
|
137
|
+
# objects, but rather than invoking individual handlers for each
|
138
|
+
# method call invokes single handler before and single after call
|
139
|
+
# which receives except arguments or result the method name.
|
140
|
+
#
|
141
|
+
# Also doesn't support customizing the arguments or result.
|
142
|
+
#
|
143
|
+
# @param [Object] object proxied object
|
144
|
+
# @return [Class] anonymous proxy class with before and after
|
145
|
+
# handlers functionality
|
146
|
+
# @since 0.2.0
|
147
|
+
#
|
148
|
+
|
149
|
+
def self.track(object)
|
150
|
+
cls = Class::new(object.class)
|
151
|
+
cls.instance_eval do
|
152
|
+
|
153
|
+
# Eviscerates instances methods and replace them by
|
154
|
+
# +#on_method+ invoker
|
155
|
+
|
156
|
+
public_instance_methods.each do |method|
|
157
|
+
if not method.in? [:object_id, :__send__]
|
158
|
+
define_method method do |*args, &block|
|
159
|
+
if not @before_call.nil?
|
160
|
+
@before_call.call(method, args, block)
|
161
|
+
end
|
162
|
+
|
163
|
+
result = @wrapped.send(method, *args, &block)
|
164
|
+
|
165
|
+
if not @after_call.nil?
|
166
|
+
@after_call.call(method, result)
|
167
|
+
end
|
168
|
+
|
169
|
+
return result
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# Adds constructor
|
175
|
+
|
176
|
+
define_method :initialize do |wrapped|
|
177
|
+
@wrapped = wrapped
|
178
|
+
@before_call = nil
|
179
|
+
@after_call = nil
|
180
|
+
end
|
181
|
+
|
182
|
+
# Defines handler assigners
|
183
|
+
|
184
|
+
define_method :before_call do |&block|
|
185
|
+
@before_call = block
|
186
|
+
end
|
187
|
+
|
188
|
+
define_method :after_call do |&block|
|
189
|
+
@after_call = block
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
return cls::new(object)
|
195
|
+
end
|
196
|
+
|
197
|
+
##
|
198
|
+
# Creates "catching object". It means, it catches all method calls
|
199
|
+
# and forwards them to +#method_call+ handler which calls wrapped object
|
200
|
+
# by default, but can be overriden, so calls can be controlled.
|
201
|
+
#
|
202
|
+
# @param [Object] object proxied object
|
203
|
+
# @return [Class] anonymous proxy class
|
204
|
+
# @since 0.2.0
|
205
|
+
#
|
206
|
+
|
207
|
+
def self.catch(object)
|
208
|
+
cls = Class::new(object.class)
|
209
|
+
cls.instance_eval do
|
210
|
+
|
211
|
+
# Eviscerates instances methods and replace them by
|
212
|
+
# +#handle_call+ invoker
|
213
|
+
|
214
|
+
public_instance_methods.each do |method|
|
215
|
+
if not method.in? [:object_id, :__send__]
|
216
|
+
define_method method do |*args, &block|
|
217
|
+
@method_call.call(method, args, block)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Adds constructor
|
223
|
+
|
224
|
+
define_method :initialize do |wrapped|
|
225
|
+
@wrapped = wrapped
|
226
|
+
@method_call = Proc::new do |method, args, block|
|
227
|
+
@wrapped.send(method, *args, &block)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
# Defines handler assigner
|
232
|
+
|
233
|
+
define_method :method_call do |&block|
|
234
|
+
@method_call = block
|
235
|
+
end
|
236
|
+
|
237
|
+
# Adds wrapped accessor
|
238
|
+
|
239
|
+
define_method :wrapped do
|
240
|
+
@wrapped
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
return cls::new(object)
|
246
|
+
end
|
90
247
|
end
|
248
|
+
|
249
|
+
##
|
250
|
+
# Alias for {ObjectProxy}.
|
251
|
+
#
|
252
|
+
|
253
|
+
OP = ObjectProxy
|
254
|
+
|
data/object-proxy.gemspec
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "object-proxy"
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Martin
|
12
|
-
s.date =
|
13
|
-
s.email =
|
11
|
+
s.authors = ["Martin Koz\u{e1}k"]
|
12
|
+
s.date = "2011-10-19"
|
13
|
+
s.email = "martinkozak@martinkozak.net"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
16
16
|
"README.md"
|
@@ -27,30 +27,30 @@ Gem::Specification.new do |s|
|
|
27
27
|
"object-proxy.gemspec",
|
28
28
|
"test"
|
29
29
|
]
|
30
|
-
s.homepage =
|
30
|
+
s.homepage = "http://github.com/martinkozak/object-proxy"
|
31
31
|
s.licenses = ["MIT"]
|
32
32
|
s.require_paths = ["lib"]
|
33
|
-
s.rubygems_version =
|
34
|
-
s.summary =
|
33
|
+
s.rubygems_version = "1.8.11"
|
34
|
+
s.summary = "Provides collection of four proxy objects intended for intercepting calls to instance methods. Works as intermediate layer between caller and called. Allows to invoke an handler both before method call and adjust its arguments and after call and post-proccess result. Aimed as tool for instant adapting the complex objects without complete deriving and extending whole classes in cases, where isn't possible to derive them as homogenic functional units or where it's simply impractical to derive them."
|
35
35
|
|
36
36
|
if s.respond_to? :specification_version then
|
37
37
|
s.specification_version = 3
|
38
38
|
|
39
39
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
-
s.add_runtime_dependency(%q<hash-utils>, [">= 0.12.
|
41
|
-
s.add_development_dependency(%q<bundler>, ["
|
42
|
-
s.add_development_dependency(%q<jeweler>, ["
|
40
|
+
s.add_runtime_dependency(%q<hash-utils>, [">= 0.12.1"])
|
41
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
42
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
|
43
43
|
s.add_development_dependency(%q<riot>, [">= 0.12.1"])
|
44
44
|
else
|
45
|
-
s.add_dependency(%q<hash-utils>, [">= 0.12.
|
46
|
-
s.add_dependency(%q<bundler>, ["
|
47
|
-
s.add_dependency(%q<jeweler>, ["
|
45
|
+
s.add_dependency(%q<hash-utils>, [">= 0.12.1"])
|
46
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
47
|
+
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
48
48
|
s.add_dependency(%q<riot>, [">= 0.12.1"])
|
49
49
|
end
|
50
50
|
else
|
51
|
-
s.add_dependency(%q<hash-utils>, [">= 0.12.
|
52
|
-
s.add_dependency(%q<bundler>, ["
|
53
|
-
s.add_dependency(%q<jeweler>, ["
|
51
|
+
s.add_dependency(%q<hash-utils>, [">= 0.12.1"])
|
52
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
53
|
+
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
54
54
|
s.add_dependency(%q<riot>, [">= 0.12.1"])
|
55
55
|
end
|
56
56
|
end
|
data/test
CHANGED
@@ -7,7 +7,7 @@ require "object-proxy"
|
|
7
7
|
require "riot"
|
8
8
|
|
9
9
|
context "ObjectProxy" do
|
10
|
-
asserts("
|
10
|
+
asserts("#create") do
|
11
11
|
s = OP["a,b,c,d"]
|
12
12
|
|
13
13
|
s.register_handler(:"before_<<") do |args|
|
@@ -21,4 +21,43 @@ context "ObjectProxy" do
|
|
21
21
|
|
22
22
|
(s << ",1,2,3" == "alfa beta") and (s == "a,b,c,d,A,B,C")
|
23
23
|
end
|
24
|
+
asserts("#fake") do
|
25
|
+
pr = OP::fake(String) do
|
26
|
+
define_method :to_s do
|
27
|
+
"alfa beta"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
pr = pr::new
|
32
|
+
(pr.to_s == "alfa beta") and pr.inspect.nil?
|
33
|
+
end
|
34
|
+
asserts("#track") do
|
35
|
+
log = [ ]
|
36
|
+
s = OP::track("a,b,c,d")
|
37
|
+
s.before_call do |name|
|
38
|
+
log << name
|
39
|
+
end
|
40
|
+
s.after_call do |name|
|
41
|
+
log << name
|
42
|
+
end
|
43
|
+
s.gsub!(",", "")
|
44
|
+
|
45
|
+
(log == [:gsub!, :gsub!]) and (s == "abcd")
|
46
|
+
end
|
47
|
+
asserts("#catch") do
|
48
|
+
s = OP::catch("alfa")
|
49
|
+
log = [ ]
|
50
|
+
|
51
|
+
s.method_call do |name, args, block|
|
52
|
+
if name == :to_s
|
53
|
+
log << name
|
54
|
+
s.wrapped.send(name, *args, &block)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
s.replace("beta")
|
59
|
+
s.to_s
|
60
|
+
|
61
|
+
(log == [:to_s]) and (s.to_s == "alfa")
|
62
|
+
end
|
24
63
|
end
|
metadata
CHANGED
@@ -1,72 +1,68 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: object-proxy
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.1.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
7
|
+
authors:
|
8
|
+
- Martin Kozák
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-10-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: hash-utils
|
18
|
-
requirement: &
|
16
|
+
requirement: &11263140 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.12.
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.12.1
|
24
22
|
type: :runtime
|
25
23
|
prerelease: false
|
26
|
-
version_requirements: *
|
27
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *11263140
|
25
|
+
- !ruby/object:Gem::Dependency
|
28
26
|
name: bundler
|
29
|
-
requirement: &
|
27
|
+
requirement: &11261480 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
34
32
|
version: 1.0.0
|
35
33
|
type: :development
|
36
34
|
prerelease: false
|
37
|
-
version_requirements: *
|
38
|
-
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: *11261480
|
36
|
+
- !ruby/object:Gem::Dependency
|
39
37
|
name: jeweler
|
40
|
-
requirement: &
|
38
|
+
requirement: &11245700 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
45
43
|
version: 1.5.2
|
46
44
|
type: :development
|
47
45
|
prerelease: false
|
48
|
-
version_requirements: *
|
49
|
-
- !ruby/object:Gem::Dependency
|
46
|
+
version_requirements: *11245700
|
47
|
+
- !ruby/object:Gem::Dependency
|
50
48
|
name: riot
|
51
|
-
requirement: &
|
49
|
+
requirement: &11244320 !ruby/object:Gem::Requirement
|
52
50
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
56
54
|
version: 0.12.1
|
57
55
|
type: :development
|
58
56
|
prerelease: false
|
59
|
-
version_requirements: *
|
57
|
+
version_requirements: *11244320
|
60
58
|
description:
|
61
59
|
email: martinkozak@martinkozak.net
|
62
60
|
executables: []
|
63
|
-
|
64
61
|
extensions: []
|
65
|
-
|
66
|
-
extra_rdoc_files:
|
62
|
+
extra_rdoc_files:
|
67
63
|
- LICENSE.txt
|
68
64
|
- README.md
|
69
|
-
files:
|
65
|
+
files:
|
70
66
|
- .document
|
71
67
|
- Gemfile
|
72
68
|
- Gemfile.lock
|
@@ -77,36 +73,38 @@ files:
|
|
77
73
|
- lib/object-proxy.rb
|
78
74
|
- object-proxy.gemspec
|
79
75
|
- test
|
80
|
-
has_rdoc: true
|
81
76
|
homepage: http://github.com/martinkozak/object-proxy
|
82
|
-
licenses:
|
77
|
+
licenses:
|
83
78
|
- MIT
|
84
79
|
post_install_message:
|
85
80
|
rdoc_options: []
|
86
|
-
|
87
|
-
require_paths:
|
81
|
+
require_paths:
|
88
82
|
- lib
|
89
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
84
|
none: false
|
91
|
-
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
|
95
|
-
segments:
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
segments:
|
96
90
|
- 0
|
97
|
-
|
98
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
hash: -3593374203948999823
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
93
|
none: false
|
100
|
-
requirements:
|
101
|
-
- -
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version:
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
104
98
|
requirements: []
|
105
|
-
|
106
99
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.
|
100
|
+
rubygems_version: 1.8.11
|
108
101
|
signing_key:
|
109
102
|
specification_version: 3
|
110
|
-
summary: Provides proxy objects intended for intercepting calls
|
103
|
+
summary: Provides collection of four proxy objects intended for intercepting calls
|
104
|
+
to instance methods. Works as intermediate layer between caller and called. Allows
|
105
|
+
to invoke an handler both before method call and adjust its arguments and after
|
106
|
+
call and post-proccess result. Aimed as tool for instant adapting the complex objects
|
107
|
+
without complete deriving and extending whole classes in cases, where isn't possible
|
108
|
+
to derive them as homogenic functional units or where it's simply impractical to
|
109
|
+
derive them.
|
111
110
|
test_files: []
|
112
|
-
|