remix 0.4.7-i386-mingw32 → 0.4.8-i386-mingw32
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/CHANGELOG +4 -0
- data/lib/remix.rb +53 -5
- data/lib/remix/version.rb +1 -1
- metadata +2 -5
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
15/11/2010 version 0.4.8
|
2
|
+
* all extend-based methods now return self
|
3
|
+
* added documentation on blocks (@yield)
|
4
|
+
* threadsafe temp_* methods now return value of block
|
1
5
|
12/11/2010 version 0.4.6
|
2
6
|
* fixed segfault in replace_module when trying to replace root module
|
3
7
|
12/11/2010 version 0.4.5
|
data/lib/remix.rb
CHANGED
@@ -20,6 +20,7 @@ rescue LoadError => e
|
|
20
20
|
end
|
21
21
|
|
22
22
|
module Kernel
|
23
|
+
|
23
24
|
# Define a `singleton_class` method for the 1.8 kids
|
24
25
|
# @return [Class] The singleton class of the receiver
|
25
26
|
def singleton_class
|
@@ -32,6 +33,7 @@ module Remix
|
|
32
33
|
# Wraps a block of code so that `before` and `after` lambdas are invoked
|
33
34
|
# prior to and after the block.
|
34
35
|
# @return [Object] The return value of the block
|
36
|
+
# @yield the block to wrap
|
35
37
|
def self.wrap_with_hooks(before, after, &block)
|
36
38
|
before.call if before
|
37
39
|
yield
|
@@ -44,6 +46,8 @@ module Remix
|
|
44
46
|
# Temporarily extends a module for the duration of a block.
|
45
47
|
# Module will be unextended at end of block.
|
46
48
|
# @param [Module] mod Module to be temporarily extended
|
49
|
+
# @return [Object] The value of the block
|
50
|
+
# @yield The block that will acquire the functionality.
|
47
51
|
# @example
|
48
52
|
# module M
|
49
53
|
# def hello
|
@@ -53,7 +57,7 @@ module Remix
|
|
53
57
|
#
|
54
58
|
# o = Object.new
|
55
59
|
# o.temp_extend(M) do
|
56
|
-
# puts hello #=> "hello"
|
60
|
+
# puts o.hello #=> "hello"
|
57
61
|
# end
|
58
62
|
#
|
59
63
|
# o.hello #=> NoMethodError
|
@@ -71,7 +75,11 @@ module Remix
|
|
71
75
|
# Temporarily extends a module for the duration of a block in a
|
72
76
|
# thread-safe manner.
|
73
77
|
# Module will be unextended at end of block.
|
78
|
+
# **DO NOT** wait on other threads in this block as it will result
|
79
|
+
# in deadlock. `Thread.exclusive` is used.
|
74
80
|
# @param [Module] mod Module to be temporarily extended
|
81
|
+
# @return [Object] The value of the block
|
82
|
+
# @yield The block that will acquire the functionality.
|
75
83
|
def temp_extend_safe(mod, options={}, &block)
|
76
84
|
safe_code = proc do
|
77
85
|
Remix.wrap_with_hooks(options[:before], options[:after]) do
|
@@ -85,74 +93,101 @@ module Remix
|
|
85
93
|
end
|
86
94
|
|
87
95
|
if !Thread.current[:__exclusive__]
|
88
|
-
|
89
|
-
|
96
|
+
value = nil
|
97
|
+
|
98
|
+
Thread.exclusive do
|
99
|
+
Thread.current[:__exclusive__] = true
|
100
|
+
value = safe_code.call
|
101
|
+
Thread.current[:__exclusive__] = false
|
102
|
+
end
|
103
|
+
|
104
|
+
value
|
90
105
|
else
|
91
106
|
safe_code.call
|
92
107
|
end
|
93
108
|
end
|
94
109
|
|
95
110
|
# Like `include_at()` but for the singleton class
|
111
|
+
# @return [Object] The receiver
|
96
112
|
# @see Remix::ModuleExtensions#include_at
|
97
113
|
def extend_at(index, mod)
|
98
114
|
singleton_class.include_at(index, mod)
|
115
|
+
self
|
99
116
|
end
|
100
117
|
|
101
118
|
# Like `include_below()` but for the singleton class
|
119
|
+
# @return [Object] The receiver
|
102
120
|
# @see Remix::ModuleExtensions#include_below
|
103
121
|
def extend_below(mod1, mod2)
|
104
122
|
singleton_class.include_below(mod1, mod2)
|
123
|
+
self
|
105
124
|
end
|
106
125
|
alias_method :extend_before, :extend_below
|
107
126
|
|
108
127
|
# Like `include_above()` but for the singleton class
|
128
|
+
# @return [Object] The receiver
|
109
129
|
# @see Remix::ModuleExtensions#include_above
|
110
130
|
def extend_above(mod1, mod2)
|
111
131
|
singleton_class.include_above(mod1, mod2)
|
132
|
+
self
|
112
133
|
end
|
113
134
|
alias_method :extend_after, :extend_above
|
114
135
|
|
115
136
|
# Like `uninclude()` but for the singleton class
|
137
|
+
# @return [Object] The receiver
|
116
138
|
# @see Remix::ModuleExtensions#uninclude
|
117
139
|
def unextend(mod, recurse = false)
|
118
140
|
singleton_class.uninclude(mod, recurse)
|
141
|
+
self
|
119
142
|
end
|
120
143
|
alias_method :remove_extended_module, :unextend
|
121
144
|
|
122
145
|
# Like `include_at_top()` but for the singleton class
|
146
|
+
# @return [Object] The receiver
|
123
147
|
# @see Remix::ModuleExtensions#include_at_top
|
124
148
|
def extend_at_top(mod)
|
125
149
|
singleton_class.include_at_top(mod)
|
150
|
+
self
|
126
151
|
end
|
127
152
|
|
128
153
|
# Like `swap_modules()` but for the singleton class
|
154
|
+
# @return [Object] The receiver
|
129
155
|
# @see Remix::ModuleExtensions#swap_modules
|
130
156
|
def swap_extended_modules(mod1, mod2)
|
131
157
|
singleton_class.swap_modules(mod1, mod2)
|
158
|
+
self
|
132
159
|
end
|
133
160
|
|
134
161
|
# Like `module_move_up()` but for the singleton class
|
162
|
+
# @return [Object] The receiver
|
135
163
|
# @see Remix::ModuleExtensions#module_move_up
|
136
164
|
def extended_module_move_up(mod)
|
137
165
|
singleton_class.module_move_up(mod)
|
166
|
+
self
|
138
167
|
end
|
139
168
|
|
140
169
|
# Like `module_move_down()` but for the singleton class
|
170
|
+
# @return [Object] The receiver
|
141
171
|
# @see Remix::ModuleExtensions#module_move_down
|
142
172
|
def extended_module_move_down(mod)
|
143
173
|
singleton_class.module_move_down(mod)
|
174
|
+
self
|
144
175
|
end
|
145
176
|
|
146
177
|
# Like `replace_module()` but for the singleton class
|
178
|
+
# @return [Object] The receiver
|
147
179
|
# @see Remix::ModuleExtensions#replace_module
|
148
180
|
def replace_extended_module(mod1, mod2)
|
149
181
|
singleton_class.replace_module(mod1, mod2)
|
182
|
+
self
|
150
183
|
end
|
151
184
|
|
152
185
|
# Like `ready_remix()` on `Module` but for the singleton class
|
186
|
+
# @return [Object] The receiver
|
153
187
|
# @see Remix::ModuleExtensions#ready_remix
|
154
188
|
def ready_remix()
|
155
189
|
singleton_class.ready_remix
|
190
|
+
self
|
156
191
|
end
|
157
192
|
end
|
158
193
|
|
@@ -161,6 +196,8 @@ module Remix
|
|
161
196
|
# Temporarily includes a module for the duration of a block.
|
162
197
|
# Module will be unincluded at end of block.
|
163
198
|
# @param [Module] mod Module to be temporarily included
|
199
|
+
# @return [Object] The value of the block
|
200
|
+
# @yield The block that will acquire the functionality.
|
164
201
|
# @example
|
165
202
|
# module M
|
166
203
|
# def hello
|
@@ -187,7 +224,11 @@ module Remix
|
|
187
224
|
# Temporarily includes a module for the duration of a block in a
|
188
225
|
# thread-safe manner.
|
189
226
|
# Module will be unincluded at end of block.
|
227
|
+
# *DO NOT* wait on other threads in this block as it will result
|
228
|
+
# in deadlock. `Thread.exclusive` is used.
|
190
229
|
# @param [Module] mod Module to be temporarily included
|
230
|
+
# @return [Object] The value of the block
|
231
|
+
# @yield The block that will acquire the functionality.
|
191
232
|
def temp_include_safe(mod, options={}, &block)
|
192
233
|
safe_code = proc do
|
193
234
|
Remix.wrap_with_hooks(options[:before], options[:after]) do
|
@@ -201,8 +242,15 @@ module Remix
|
|
201
242
|
end
|
202
243
|
|
203
244
|
if !Thread.current[:__exclusive__]
|
204
|
-
|
205
|
-
|
245
|
+
value = nil
|
246
|
+
|
247
|
+
Thread.exclusive do
|
248
|
+
Thread.current[:__exclusive__] = true
|
249
|
+
value = safe_code.call
|
250
|
+
Thread.current[:__exclusive__] = false
|
251
|
+
end
|
252
|
+
|
253
|
+
value
|
206
254
|
else
|
207
255
|
safe_code.call
|
208
256
|
end
|
data/lib/remix/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 1
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
8
|
+
- 8
|
9
|
+
version: 0.4.8
|
11
10
|
platform: i386-mingw32
|
12
11
|
authors:
|
13
12
|
- John Mair (banisterfiend)
|
@@ -55,7 +54,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
54
|
requirements:
|
56
55
|
- - ">="
|
57
56
|
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
57
|
segments:
|
60
58
|
- 0
|
61
59
|
version: "0"
|
@@ -64,7 +62,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
62
|
requirements:
|
65
63
|
- - ">="
|
66
64
|
- !ruby/object:Gem::Version
|
67
|
-
hash: 3
|
68
65
|
segments:
|
69
66
|
- 0
|
70
67
|
version: "0"
|