wrap 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +2 -3
- data/lib/wrap.rb +20 -1
- data/test/wrap_test.rb +42 -0
- data/wrap.gemspec +1 -1
- metadata +4 -4
data/README
CHANGED
@@ -2,10 +2,10 @@ NAME
|
|
2
2
|
wrap
|
3
3
|
|
4
4
|
SYNOPSIS
|
5
|
-
non-sucking :before and :after
|
5
|
+
non-sucking :before and :after filters for any ruby class
|
6
6
|
|
7
7
|
DESCRIPTION
|
8
|
-
yes yes, active_support does this. but crapily. with
|
8
|
+
yes yes, active_support does this. but crapily. with active_support you'll
|
9
9
|
need to do this
|
10
10
|
|
11
11
|
|
@@ -55,4 +55,3 @@ DESCRIPTION
|
|
55
55
|
will be called with the result of the wrapped method, iff possible.
|
56
56
|
|
57
57
|
the test suite reads pretty damn clean. have a go.
|
58
|
-
|
data/lib/wrap.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
##
|
6
6
|
#
|
7
7
|
class << Wrap
|
8
|
-
Version = '0.
|
8
|
+
Version = '0.6.0' unless defined?(Version)
|
9
9
|
|
10
10
|
def version
|
11
11
|
Version
|
@@ -156,14 +156,33 @@
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def before(name, *args, &block)
|
159
|
+
name = wrap_expand_aliases(name)
|
159
160
|
cb = initialize_callbacks!(name)
|
160
161
|
cb.before.push(args.shift || block)
|
161
162
|
end
|
162
163
|
|
163
164
|
def after(name, *args, &block)
|
165
|
+
name = wrap_expand_aliases(name)
|
164
166
|
cb = initialize_callbacks!(name)
|
165
167
|
cb.after.push(args.shift || block)
|
166
168
|
end
|
169
|
+
|
170
|
+
def wrap_aliases
|
171
|
+
@@wrap_aliases ||= Hash.new
|
172
|
+
end
|
173
|
+
|
174
|
+
def wrap_alias(dst, src)
|
175
|
+
wrap_aliases[dst.to_s] = src.to_s
|
176
|
+
end
|
177
|
+
|
178
|
+
def wrap_expand_aliases(name)
|
179
|
+
name = name.to_s
|
180
|
+
loop do
|
181
|
+
break unless wrap_aliases.has_key?(name)
|
182
|
+
name = wrap_aliases[name]
|
183
|
+
end
|
184
|
+
name
|
185
|
+
end
|
167
186
|
end
|
168
187
|
|
169
188
|
InstanceMethods = proc do
|
data/test/wrap_test.rb
CHANGED
@@ -242,6 +242,48 @@ Testing Wrap do
|
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
245
|
+
|
246
|
+
##
|
247
|
+
#
|
248
|
+
testing 'that wrap aliases can be defined as syntax sugar' do
|
249
|
+
c =
|
250
|
+
assert do
|
251
|
+
wrapped_class do
|
252
|
+
define_method(:run_validations){ accum.push(:during); accum }
|
253
|
+
|
254
|
+
wrap :run_validations
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
assert do
|
259
|
+
o = c.new
|
260
|
+
o.run_validations()
|
261
|
+
o.accum
|
262
|
+
assert o.accum === [:during]
|
263
|
+
end
|
264
|
+
|
265
|
+
c.class_eval do
|
266
|
+
wrap_alias :validation, :run_validations
|
267
|
+
|
268
|
+
before(:validation){ accum.push(:before) }
|
269
|
+
after(:validation){ accum.push(:after) }
|
270
|
+
end
|
271
|
+
|
272
|
+
assert do
|
273
|
+
o = c.new
|
274
|
+
o.run_validations()
|
275
|
+
o.accum
|
276
|
+
assert o.accum === [:before, :during, :after]
|
277
|
+
end
|
278
|
+
|
279
|
+
assert do
|
280
|
+
o = Class.new(c).new
|
281
|
+
o.run_validations()
|
282
|
+
o.accum
|
283
|
+
assert o.accum === [:before, :during, :after]
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
245
287
|
private
|
246
288
|
def wrapped_class(&block)
|
247
289
|
tc = self
|
data/wrap.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-12-
|
12
|
+
date: 2011-12-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: map
|
16
|
-
requirement: &
|
16
|
+
requirement: &70247178773500 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 4.7.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70247178773500
|
25
25
|
description: ! 'description: wrap kicks the ass'
|
26
26
|
email: ara.t.howard@gmail.com
|
27
27
|
executables: []
|