proxeze 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -123,6 +123,89 @@ Note: I don't recommend overriding the #hash method on your class, this serves o
123
123
  == Method Interceptions
124
124
  Proxeze has the ability to surround instance method calls with _before_ and _after_ callbacks. This support was lifted straight from proxy_machine (https://github.com/tulios/proxy_machine).
125
125
 
126
+ === Defining callbacks at the method level
127
+
128
+ ==== before
129
+
130
+ p = Proxeze.for [0, 1, 2, 3] do
131
+ before :reverse do |obj, args|
132
+ obj << obj.length
133
+ end
134
+ end
135
+
136
+ p.reverse # => [4, 3, 2, 1, 0]
137
+
138
+ ==== after
139
+
140
+ p = Proxeze.for [4, 2, 3] do
141
+ after :reverse do |obj, result, args|
142
+ result.sort
143
+ end
144
+ end
145
+
146
+ p.reverse => [4, 3, 2] # We reordered the list
147
+
148
+ You will always receive the arguments passed to the original method.
149
+
150
+ === Defining callbacks for all method calls
151
+
152
+ ==== before_all
153
+ This callback will receive a reference of the object, the symbol of the called method and the
154
+ original arguments passed.
155
+
156
+ logged = nil
157
+ p = Proxeze.for [0, 1, 2, 3] do
158
+ before_all do |obj, method, args|
159
+ logged = "before #{method} on #{obj.inspect} with args[#{args.inspect}]"
160
+ end
161
+ end
162
+ p.reverse # => [3, 2, 1, 0]
163
+ logged # => before reverse on [0, 1, 2, 3] with args[[]]
164
+
165
+ p.size => 4
166
+ logged # => before size on [0, 1, 2, 3] with args[[]]
167
+
168
+ p.unshift 9 # => [9, 0, 1, 2, 3]
169
+ logged # => before unshift on [0, 1, 2, 3] with args[[9]]
170
+
171
+ ==== after_all
172
+ This callback will receive a reference of the object, the result of execution (this result could be nil),
173
+ the symbol of the called method and the arguments passed.
174
+
175
+ logged = nil
176
+ p = Proxeze.for [1, 2, 3] do
177
+ after_all do |obj, result, method, args|
178
+ logged = "after #{method} on #{obj.inspect} with args[#{args.inspect}], result is now [#{result}]"
179
+ result
180
+ end
181
+ end
182
+ p.reverse # => [3, 2, 1]
183
+ logged # => after reverse on [1, 2, 3] with args[[]], result is now [[3, 2, 1]]
184
+
185
+ p.size # => 3
186
+ logged # => after size on [1, 2, 3] with args[[]], result is now [3]
187
+
188
+ === Registering a class to perform a callback
189
+
190
+ The constructor will receive the object, in case of an :after it will receive the result too.
191
+ You need to have a :call method. Proxeze will create a new instance of the class every time it
192
+ needs to use it. You could use this feature with the before_all and after_all too.
193
+
194
+ # Example of class
195
+ class SortPerformer
196
+ def initialize object, result = nil, method = nil, args = nil
197
+ @object = object; @result = result; @method = method, @args = args
198
+ end
199
+
200
+ def call; @object.sort! end
201
+ end
202
+
203
+ p = Proxeze.for [1, 4, 2, 3] do
204
+ after :reverse, SortPerformer
205
+ end
206
+
207
+ p.reverse => [1, 2, 3, 4]
208
+
126
209
  == Supported Ruby versions
127
210
  This code has been tested on 1.8.7, 1.9.2, and JRuby 1.5.6. I haven't bothered to test it on anything else, but I strongly suspect it will work just fine on any Ruby implementation greater than 1.8.6.
128
211
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
data/proxeze.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{proxeze}
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jason Rogers"]
data/spec/proxeze_spec.rb CHANGED
@@ -246,8 +246,7 @@ describe Proxeze do
246
246
 
247
247
  it "should be able to add hooks to a proxied instance" do
248
248
  a = Proxeze.for [0, 1, 3, 2, 5, 4] do
249
- before :reverse do |*args|
250
- target, mid, arguments = *args
249
+ before :reverse do |target, mid, arguments|
251
250
  target << target.length
252
251
  end
253
252
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: proxeze
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.0
5
+ version: 1.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jason Rogers
@@ -192,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
192
  requirements:
193
193
  - - ">="
194
194
  - !ruby/object:Gem::Version
195
- hash: 1558564409570473253
195
+ hash: -2385236588266356416
196
196
  segments:
197
197
  - 0
198
198
  version: "0"