no_backsies 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby +47 -0
- data/.yardopts +7 -0
- data/HISTORY.rdoc +20 -0
- data/QED.rdoc +3 -1
- data/README.rdoc +40 -6
- data/lib/no_backsies.rb +118 -37
- data/qed/callbacks/07_const_missing.rdoc +3 -1
- metadata +54 -54
data/.ruby
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
source:
|
3
|
+
- meta
|
4
|
+
authors:
|
5
|
+
- name: 7rans
|
6
|
+
email: transfire@gmail.com
|
7
|
+
copyrights:
|
8
|
+
- holder: Rubyworks
|
9
|
+
year: '2009'
|
10
|
+
license: BSD-2-Clause
|
11
|
+
replacements: []
|
12
|
+
alternatives: []
|
13
|
+
requirements:
|
14
|
+
- name: qed
|
15
|
+
groups:
|
16
|
+
- test
|
17
|
+
development: true
|
18
|
+
- name: detroit
|
19
|
+
groups:
|
20
|
+
- build
|
21
|
+
development: true
|
22
|
+
dependencies: []
|
23
|
+
conflicts: []
|
24
|
+
repositories: []
|
25
|
+
resources:
|
26
|
+
home: http://rubyworks.github.com/no_backsies
|
27
|
+
code: http://github.com/rubyworks/no_backsies
|
28
|
+
mail: http://googlegroups/group/rubyworks-mailinglist
|
29
|
+
docs: http://rubydoc.info/gems/no_backsies/frames
|
30
|
+
extra: {}
|
31
|
+
load_path:
|
32
|
+
- lib
|
33
|
+
revision: 0
|
34
|
+
created: '2011-04-29'
|
35
|
+
summary: Better handling of Ruby callbacks
|
36
|
+
title: NoBacksies
|
37
|
+
version: 0.3.2
|
38
|
+
name: no_backsies
|
39
|
+
description: ! 'NoBacksies is a callback layer built on top of Ruby''s built-in callback
|
40
|
+
|
41
|
+
methods. It makes it possible to add new callbacks very easily, without
|
42
|
+
|
43
|
+
having to fuss with more nuanced issues of defining and redefining callback
|
44
|
+
|
45
|
+
methods.'
|
46
|
+
organization: Rubyworks
|
47
|
+
date: '2011-10-27'
|
data/.yardopts
ADDED
data/HISTORY.rdoc
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
= RELEASE HISTORY
|
2
2
|
|
3
|
+
== 0.3.2 | 2011-10-27
|
4
|
+
|
5
|
+
This release adds support for calling super from within callback procedures.
|
6
|
+
|
7
|
+
Changes:
|
8
|
+
|
9
|
+
* Add support for calling super.
|
10
|
+
|
11
|
+
|
12
|
+
== 0.3.1 | 2011-07-06
|
13
|
+
|
14
|
+
Fix method argumements on const_missing, included, extended
|
15
|
+
and inherited callbacks.
|
16
|
+
|
17
|
+
Changes:
|
18
|
+
|
19
|
+
* Fixed callback arguments that have been copy/pasted. (blambeau)
|
20
|
+
* Add individual tests for each callback.
|
21
|
+
|
22
|
+
|
3
23
|
== 0.3.0 | 2011-07-06
|
4
24
|
|
5
25
|
This release is made primarily because the program is now
|
data/QED.rdoc
CHANGED
@@ -286,7 +286,7 @@ Given a class that defines a no-backsies +const_missing+ callback.
|
|
286
286
|
@list ||= []
|
287
287
|
end
|
288
288
|
|
289
|
-
callback :const_missing do |const|
|
289
|
+
callback :const_missing, :superless=>true do |const|
|
290
290
|
list << const
|
291
291
|
end
|
292
292
|
|
@@ -299,6 +299,8 @@ Then the results are as follows.
|
|
299
299
|
|
300
300
|
Y.list #=> [:FOO, :BAR]
|
301
301
|
|
302
|
+
Notice we used `:superless` to prevent super from being called, which would
|
303
|
+
have raised an NameError.
|
302
304
|
|
303
305
|
= Included
|
304
306
|
|
data/README.rdoc
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
= No Backsies
|
2
2
|
|
3
|
+
{Homepage}[http://rubyworks.github.com/no_backsies] |
|
4
|
+
{Development}[http://github.com/rubyworks/no_backsies] |
|
5
|
+
{Mailing List}[http://groups.google.com/group/rubyworks-mailinglist] |
|
6
|
+
{API Reference}[http://rubydoc.info/gems/no_backsies/frames] |
|
7
|
+
{Demonstrandum}[http://rubyworks.github.com/no_backsies/qed.html]
|
8
|
+
|
9
|
+
|
3
10
|
== DESCRIPTION
|
4
11
|
|
5
12
|
NoBacksies is a callback layer built on top of Ruby's built-in callback
|
@@ -8,13 +15,9 @@ having to fuss with more nuanced issues of defining and redefining callback
|
|
8
15
|
methods.
|
9
16
|
|
10
17
|
|
11
|
-
==
|
18
|
+
== Compatability
|
12
19
|
|
13
|
-
*
|
14
|
-
* {Development}[http://github.com/rubyworks/no_backsies]
|
15
|
-
* {Mailing List}[http://groups.google.com/group/rubyworks-mailinglist]
|
16
|
-
* {API Reference}[http://rubydoc.info/gems/no_backsies/frames]
|
17
|
-
* {Demonstrandum}[http://rubyworks.github.com/no_backsies/QED.html]
|
20
|
+
NoBacksies does not currently work with *Rubinius*. Anyone know why?
|
18
21
|
|
19
22
|
|
20
23
|
== EXAMPLES
|
@@ -69,6 +72,37 @@ Install the RubyGems package in the usual fashion.
|
|
69
72
|
$ gem install no_backsies
|
70
73
|
|
71
74
|
|
75
|
+
== CONTRIBUTE
|
76
|
+
|
77
|
+
=== Development
|
78
|
+
|
79
|
+
Source code is hosted on GitHub[http://github.com/rubyworks/qed].
|
80
|
+
If you'd like to submit a patch please fork the repository and
|
81
|
+
submit a pull request (ideally in a topic branch).
|
82
|
+
|
83
|
+
=== Testing
|
84
|
+
|
85
|
+
QED[http://rubyworks.github.com/qed] is used to testing.
|
86
|
+
|
87
|
+
$ gem install qed
|
88
|
+
|
89
|
+
To run the tests:
|
90
|
+
|
91
|
+
$ qed [path/to/test]
|
92
|
+
|
93
|
+
=== Donations
|
94
|
+
|
95
|
+
Software development is very time consuming. Rubyworks does a lot of FOSS
|
96
|
+
development for el <i>$0</i>. We do it for the love of programming and
|
97
|
+
for Ruby. Any dollars that do come our way help us continue
|
98
|
+
the effort. So anything you may offer will help these projects such as this
|
99
|
+
continue to flourish.
|
100
|
+
|
101
|
+
See the {Rubyworks Homepage}[http://rubyworks.github.com].
|
102
|
+
|
103
|
+
Thanks.
|
104
|
+
|
105
|
+
|
72
106
|
== LEGAL
|
73
107
|
|
74
108
|
(BSD 2 License)
|
data/lib/no_backsies.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# NoBacksies module ecapsulates all supported callback mixins.
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# NoBacksies::Callbacks can be mixed-in and all supported callbacks will
|
4
4
|
# be applied to the class or module.
|
5
5
|
#
|
6
6
|
# class Y
|
@@ -46,14 +46,50 @@
|
|
46
46
|
# y = Y.new
|
47
47
|
# y.foo! #=> "foo!"
|
48
48
|
#
|
49
|
-
#
|
50
|
-
# We will look into adding instance level callbacks in a future version.
|
49
|
+
# == Calling Super
|
51
50
|
#
|
52
|
-
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
|
51
|
+
# Each callback invocation passes along a superblock procedure, which can be
|
52
|
+
# used to invoke `super` for the underlying callback method. For example,
|
53
|
+
# it is common to call `super` in a `const_missing` callback if the dynamic
|
54
|
+
# constant lookup fails.
|
55
|
+
#
|
56
|
+
# callback :const_missing do |const, &superblock|
|
57
|
+
# psuedo_constants[const] || superblock.call
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# By default, super is called after call callback procedures are called becuase
|
61
|
+
# that is by far the most commonly desired behavior. To suppress this behavior
|
62
|
+
# pass the `:superless=>true` flag to the `callback` method.
|
63
|
+
#
|
64
|
+
# callback :included, :superless=>true do |mod|
|
65
|
+
# ...
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# == Customizing the Underlying Callback Procedure
|
69
|
+
#
|
70
|
+
# Every callback follows the same simply pattern, e.g. for `method_added`:
|
71
|
+
#
|
72
|
+
# def self.method_added(method)
|
73
|
+
# if defined?(super)
|
74
|
+
# callback_invoke(:method_added, method){ super(method) }
|
75
|
+
# else
|
76
|
+
# callback_invoke(:method_added, method)
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# So it is easy enough to customize if you have some special requirements.
|
81
|
+
# Say you want to call super before all callback procedures, and never allow
|
82
|
+
# any callback procedure to do so themselves, then you could simply redefine
|
83
|
+
# the underlying callback method as:
|
84
|
+
#
|
85
|
+
# def self.method_added(method)
|
86
|
+
# super(method) if defined?(super)
|
87
|
+
# callback_invoke(:method_added, method)
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# NOTE: Currently the NoBacksies module only supports class level callbacks.
|
91
|
+
# We will look into adding instance level callbacks, such as `method_missing`
|
92
|
+
# in a future version.
|
57
93
|
|
58
94
|
module NoBacksies
|
59
95
|
|
@@ -115,23 +151,27 @@ module NoBacksies
|
|
115
151
|
end
|
116
152
|
|
117
153
|
# Invoke a callback.
|
118
|
-
|
154
|
+
#
|
155
|
+
def callback_invoke(name, *args, &superblock)
|
119
156
|
name = name.to_sym
|
120
157
|
return unless callback_express[name]
|
121
158
|
callbacks[name].each do |block, options|
|
122
159
|
if options[:safe]
|
123
160
|
callback_express(name=>false) do
|
124
|
-
block.call(*args)
|
161
|
+
block.call(*args, &superblock)
|
125
162
|
end
|
126
163
|
else
|
127
|
-
block.call(*args)
|
164
|
+
block.call(*args, &superblock)
|
128
165
|
end
|
129
166
|
if options[:once]
|
130
167
|
callbacks[name].delete([block, options])
|
131
168
|
end
|
169
|
+
if !options[:superless]
|
170
|
+
superblock.call if superblock
|
171
|
+
end
|
132
172
|
end
|
133
173
|
end
|
134
|
-
end
|
174
|
+
end #module
|
135
175
|
|
136
176
|
# Callback system for #method_added.
|
137
177
|
module MethodAdded
|
@@ -143,7 +183,11 @@ module NoBacksies
|
|
143
183
|
|
144
184
|
#
|
145
185
|
def method_added(method)
|
146
|
-
|
186
|
+
if defined?(super)
|
187
|
+
callback_invoke(:method_added, method){ super(method) }
|
188
|
+
else
|
189
|
+
callback_invoke(:method_added, method)
|
190
|
+
end
|
147
191
|
end
|
148
192
|
end
|
149
193
|
|
@@ -157,7 +201,11 @@ module NoBacksies
|
|
157
201
|
|
158
202
|
#
|
159
203
|
def method_removed(method)
|
160
|
-
|
204
|
+
if defined?(super)
|
205
|
+
callback_invoke(:method_removed, method){ super(method) }
|
206
|
+
else
|
207
|
+
callback_invoke(:method_removed, method)
|
208
|
+
end
|
161
209
|
end
|
162
210
|
end
|
163
211
|
|
@@ -171,7 +219,11 @@ module NoBacksies
|
|
171
219
|
|
172
220
|
#
|
173
221
|
def method_undefined(method)
|
174
|
-
|
222
|
+
if defined?(super)
|
223
|
+
callback_invoke(:method_undefined, method){ super(method) }
|
224
|
+
else
|
225
|
+
callback_invoke(:method_undefined, method)
|
226
|
+
end
|
175
227
|
end
|
176
228
|
end
|
177
229
|
|
@@ -185,11 +237,15 @@ module NoBacksies
|
|
185
237
|
|
186
238
|
#
|
187
239
|
def singleton_method_added(method)
|
188
|
-
|
240
|
+
if defined?(super)
|
241
|
+
callback_invoke(:singleton_method_added, method){ super(method) }
|
242
|
+
else
|
243
|
+
callback_invoke(:singleton_method_added, method)
|
244
|
+
end
|
189
245
|
end
|
190
246
|
end
|
191
247
|
|
192
|
-
# Callback system for #
|
248
|
+
# Callback system for #singleton_method_removed.
|
193
249
|
module SingletonMethodRemoved
|
194
250
|
#
|
195
251
|
def self.append_features(base)
|
@@ -199,11 +255,15 @@ module NoBacksies
|
|
199
255
|
|
200
256
|
#
|
201
257
|
def singleton_method_removed(method)
|
202
|
-
|
258
|
+
if defined?(super)
|
259
|
+
callback_invoke(:singleton_method_removed, method){ super(method) }
|
260
|
+
else
|
261
|
+
callback_invoke(:singleton_method_removed, method)
|
262
|
+
end
|
203
263
|
end
|
204
264
|
end
|
205
265
|
|
206
|
-
# Callback system for #
|
266
|
+
# Callback system for #singleton_method_undefined.
|
207
267
|
module SingletonMethodUndefined
|
208
268
|
#
|
209
269
|
def self.append_features(base)
|
@@ -213,12 +273,16 @@ module NoBacksies
|
|
213
273
|
|
214
274
|
#
|
215
275
|
def singleton_method_undefined(method)
|
216
|
-
|
276
|
+
if defined?(super)
|
277
|
+
callback_invoke(:singleton_method_undefined, method){ super(method) }
|
278
|
+
else
|
279
|
+
callback_invoke(:singleton_method_undefined, method)
|
280
|
+
end
|
217
281
|
end
|
218
282
|
end
|
219
283
|
|
220
|
-
# Callback system for #
|
221
|
-
module
|
284
|
+
# Callback system for #included.
|
285
|
+
module Included
|
222
286
|
#
|
223
287
|
def self.append_features(base)
|
224
288
|
base.extend CallbackMethods
|
@@ -226,13 +290,17 @@ module NoBacksies
|
|
226
290
|
end
|
227
291
|
|
228
292
|
#
|
229
|
-
def
|
230
|
-
|
293
|
+
def included(mod)
|
294
|
+
if defined?(super)
|
295
|
+
callback_invoke(:included, mod){ super(mod) }
|
296
|
+
else
|
297
|
+
callback_invoke(:included, mod)
|
298
|
+
end
|
231
299
|
end
|
232
300
|
end
|
233
301
|
|
234
|
-
# Callback system for #
|
235
|
-
module
|
302
|
+
# Callback system for #extended.
|
303
|
+
module Extended
|
236
304
|
#
|
237
305
|
def self.append_features(base)
|
238
306
|
base.extend CallbackMethods
|
@@ -240,13 +308,17 @@ module NoBacksies
|
|
240
308
|
end
|
241
309
|
|
242
310
|
#
|
243
|
-
def
|
244
|
-
|
311
|
+
def extended(mod)
|
312
|
+
if defined?(super)
|
313
|
+
callback_invoke(:extended, mod){ super(mod) }
|
314
|
+
else
|
315
|
+
callback_invoke(:extended, mod)
|
316
|
+
end
|
245
317
|
end
|
246
318
|
end
|
247
319
|
|
248
|
-
# Callback system for #
|
249
|
-
module
|
320
|
+
# Callback system for #inherited.
|
321
|
+
module Inherited
|
250
322
|
#
|
251
323
|
def self.append_features(base)
|
252
324
|
base.extend CallbackMethods
|
@@ -254,13 +326,19 @@ module NoBacksies
|
|
254
326
|
end
|
255
327
|
|
256
328
|
#
|
257
|
-
def
|
258
|
-
|
329
|
+
def inherited(base)
|
330
|
+
if defined?(super)
|
331
|
+
callback_invoke(:inherited, base){ super(base) }
|
332
|
+
else
|
333
|
+
callback_invoke(:inherited, base)
|
334
|
+
end
|
259
335
|
end
|
260
336
|
end
|
261
337
|
|
262
|
-
# Callback system for #
|
263
|
-
|
338
|
+
# Callback system for #const_missing.
|
339
|
+
#
|
340
|
+
# Unlike other callback mixins, this does NOT invoke super (for obvious reasons).
|
341
|
+
module ConstMissing
|
264
342
|
#
|
265
343
|
def self.append_features(base)
|
266
344
|
base.extend CallbackMethods
|
@@ -268,10 +346,13 @@ module NoBacksies
|
|
268
346
|
end
|
269
347
|
|
270
348
|
#
|
271
|
-
def
|
272
|
-
|
349
|
+
def const_missing(const)
|
350
|
+
if defined?(super)
|
351
|
+
callback_invoke(:const_missing, const){ super(const) }
|
352
|
+
else
|
353
|
+
callback_invoke(:const_missing, const)
|
354
|
+
end
|
273
355
|
end
|
274
356
|
end
|
275
357
|
|
276
358
|
end
|
277
|
-
|
@@ -9,7 +9,7 @@ Given a class that defines a no-backsies +const_missing+ callback.
|
|
9
9
|
@list ||= []
|
10
10
|
end
|
11
11
|
|
12
|
-
callback :const_missing do |const|
|
12
|
+
callback :const_missing, :superless=>true do |const|
|
13
13
|
list << const
|
14
14
|
end
|
15
15
|
|
@@ -22,3 +22,5 @@ Then the results are as follows.
|
|
22
22
|
|
23
23
|
Y.list #=> [:FOO, :BAR]
|
24
24
|
|
25
|
+
Notice we used `:superless` to prevent super from being called, which would
|
26
|
+
have raised an NameError.
|
metadata
CHANGED
@@ -1,52 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: no_backsies
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
4
5
|
prerelease:
|
5
|
-
version: 0.3.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
7
|
+
authors:
|
8
|
+
- 7rans
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-10-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: qed
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &18797320 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
24
22
|
type: :development
|
25
|
-
version_requirements: *id001
|
26
|
-
- !ruby/object:Gem::Dependency
|
27
|
-
name: detroit
|
28
23
|
prerelease: false
|
29
|
-
|
24
|
+
version_requirements: *18797320
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: detroit
|
27
|
+
requirement: &18712220 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
35
33
|
type: :development
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *18712220
|
36
|
+
description: ! 'NoBacksies is a callback layer built on top of Ruby''s built-in callback
|
37
|
+
|
39
38
|
methods. It makes it possible to add new callbacks very easily, without
|
39
|
+
|
40
40
|
having to fuss with more nuanced issues of defining and redefining callback
|
41
|
-
methods.
|
42
|
-
email: transfire@gmail.com
|
43
|
-
executables: []
|
44
41
|
|
42
|
+
methods.'
|
43
|
+
email:
|
44
|
+
- transfire@gmail.com
|
45
|
+
executables: []
|
45
46
|
extensions: []
|
46
|
-
|
47
|
-
|
47
|
+
extra_rdoc_files:
|
48
|
+
- HISTORY.rdoc
|
48
49
|
- README.rdoc
|
49
|
-
|
50
|
+
- QED.rdoc
|
51
|
+
- COPYING.rdoc
|
52
|
+
- NOTICE.rdoc
|
53
|
+
files:
|
54
|
+
- .ruby
|
55
|
+
- .yardopts
|
50
56
|
- lib/no_backsies.rb
|
51
57
|
- qed/01_example.rdoc
|
52
58
|
- qed/02_express.rdoc
|
@@ -68,34 +74,28 @@ files:
|
|
68
74
|
- COPYING.rdoc
|
69
75
|
- NOTICE.rdoc
|
70
76
|
homepage: http://rubyworks.github.com/no_backsies
|
71
|
-
licenses:
|
72
|
-
|
77
|
+
licenses:
|
78
|
+
- BSD-2-Clause
|
73
79
|
post_install_message:
|
74
|
-
rdoc_options:
|
75
|
-
|
76
|
-
- NoBacksies API
|
77
|
-
- --main
|
78
|
-
- README.rdoc
|
79
|
-
require_paths:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
80
82
|
- lib
|
81
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
84
|
none: false
|
83
|
-
requirements:
|
84
|
-
- -
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
version:
|
87
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
90
|
none: false
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version:
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
93
95
|
requirements: []
|
94
|
-
|
95
|
-
|
96
|
-
rubygems_version: 1.8.2
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.10
|
97
98
|
signing_key:
|
98
99
|
specification_version: 3
|
99
100
|
summary: Better handling of Ruby callbacks
|
100
101
|
test_files: []
|
101
|
-
|