remix 0.3.4-i386-mingw32 → 0.4.0-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 +3 -0
- data/README.markdown +1 -1
- data/Rakefile +3 -6
- data/ext/remix/remix.c +15 -15
- data/lib/1.8/remix.so +0 -0
- data/lib/1.9/remix.so +0 -0
- data/lib/remix/version.rb +1 -1
- data/lib/remix.rb +72 -0
- data/test/test.rb +43 -2
- data/test/test_with_object2module.rb +1 -0
- metadata +6 -3
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -79,7 +79,7 @@ Remix is one of a series of experimental libraries that mess with
|
|
79
79
|
the internals of Ruby to bring new and interesting functionality to
|
80
80
|
the language, see also:
|
81
81
|
|
82
|
-
* [
|
82
|
+
* [Include Complete](http://github.com/banister/include_complete) - Brings in
|
83
83
|
module singleton classes during an include. No more ugly ClassMethods and included() hook hacks.
|
84
84
|
* [Object2module](http://github.com/banister/object2module) - Convert Classes and Objects to Modules so they can be extended/included
|
85
85
|
* [Prepend](http://github.com/banister/prepend) - Prepends modules in front of a class; so method lookup starts with the module
|
data/Rakefile
CHANGED
@@ -28,8 +28,9 @@ task :test do
|
|
28
28
|
sh "bacon -k #{direc}/test/test.rb"
|
29
29
|
end
|
30
30
|
|
31
|
+
|
31
32
|
[:mingw32, :mswin32].each do |v|
|
32
|
-
|
33
|
+
namespace v do
|
33
34
|
spec = Gem::Specification.new do |s|
|
34
35
|
apply_spec_defaults(s)
|
35
36
|
s.platform = "i386-#{v}"
|
@@ -40,12 +41,10 @@ end
|
|
40
41
|
pkg.need_zip = false
|
41
42
|
pkg.need_tar = false
|
42
43
|
end
|
43
|
-
|
44
|
-
Rake::Task[:gem].invoke
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
|
-
|
47
|
+
namespace :ruby do
|
49
48
|
spec = Gem::Specification.new do |s|
|
50
49
|
apply_spec_defaults(s)
|
51
50
|
s.platform = Gem::Platform::RUBY
|
@@ -56,7 +55,5 @@ task :ruby do
|
|
56
55
|
pkg.need_zip = false
|
57
56
|
pkg.need_tar = false
|
58
57
|
end
|
59
|
-
|
60
|
-
Rake::Task[:gem].invoke
|
61
58
|
end
|
62
59
|
|
data/ext/remix/remix.c
CHANGED
@@ -121,7 +121,7 @@ get_source_module(VALUE mod)
|
|
121
121
|
}
|
122
122
|
|
123
123
|
static VALUE
|
124
|
-
|
124
|
+
retrieve_imod_before_mod(VALUE m, VALUE before)
|
125
125
|
{
|
126
126
|
Validate_Type(before);
|
127
127
|
|
@@ -137,7 +137,7 @@ retrieve_before_mod(VALUE m, VALUE before)
|
|
137
137
|
}
|
138
138
|
|
139
139
|
static VALUE
|
140
|
-
|
140
|
+
retrieve_imod_for_mod(VALUE m, VALUE after)
|
141
141
|
{
|
142
142
|
Validate_Type(after);
|
143
143
|
|
@@ -161,7 +161,7 @@ rb_module_move_up(VALUE self, VALUE mod)
|
|
161
161
|
if (self == mod)
|
162
162
|
return self;
|
163
163
|
|
164
|
-
VALUE included_mod =
|
164
|
+
VALUE included_mod = retrieve_imod_for_mod(self, mod);
|
165
165
|
if (RCLASS_SUPER(included_mod) == rb_cObject || RCLASS_SUPER(included_mod) == 0)
|
166
166
|
return self;
|
167
167
|
|
@@ -178,7 +178,7 @@ rb_module_move_down(VALUE self, VALUE mod)
|
|
178
178
|
if (self == mod)
|
179
179
|
return self;
|
180
180
|
|
181
|
-
VALUE before_included_mod =
|
181
|
+
VALUE before_included_mod = retrieve_imod_before_mod(self, mod);
|
182
182
|
if (before_included_mod == self)
|
183
183
|
return self;
|
184
184
|
|
@@ -193,9 +193,9 @@ rb_include_at_top(VALUE self, VALUE mod)
|
|
193
193
|
rb_prepare_for_remix(self);
|
194
194
|
|
195
195
|
if (TYPE(self) == T_MODULE)
|
196
|
-
rb_include_module(
|
196
|
+
rb_include_module(retrieve_imod_before_mod(self, Qfalse), mod);
|
197
197
|
else
|
198
|
-
rb_include_module(
|
198
|
+
rb_include_module(retrieve_imod_before_mod(self, rb_cObject), mod);
|
199
199
|
|
200
200
|
return self;
|
201
201
|
}
|
@@ -204,7 +204,7 @@ VALUE
|
|
204
204
|
rb_include_after(VALUE self, VALUE after, VALUE mod)
|
205
205
|
{
|
206
206
|
rb_prepare_for_remix(self);
|
207
|
-
rb_include_module(
|
207
|
+
rb_include_module(retrieve_imod_for_mod(self, after), mod);
|
208
208
|
return self;
|
209
209
|
}
|
210
210
|
|
@@ -216,7 +216,7 @@ rb_include_before(VALUE self, VALUE before, VALUE mod)
|
|
216
216
|
if (before == self)
|
217
217
|
rb_raise(rb_eRuntimeError, "Prepend not supported yet!");
|
218
218
|
|
219
|
-
rb_include_module(
|
219
|
+
rb_include_module(retrieve_imod_before_mod(self, before), mod);
|
220
220
|
return self;
|
221
221
|
}
|
222
222
|
|
@@ -250,10 +250,10 @@ rb_swap_modules(VALUE self, VALUE mod1, VALUE mod2)
|
|
250
250
|
|
251
251
|
if (mod1 == rb_cObject || mod2 == rb_cObject) rb_raise(rb_eRuntimeError, "can't swap Object");
|
252
252
|
|
253
|
-
included_mod1 =
|
254
|
-
included_mod2 =
|
255
|
-
before_mod1 =
|
256
|
-
before_mod2 =
|
253
|
+
included_mod1 = retrieve_imod_for_mod(self, mod1);
|
254
|
+
included_mod2 = retrieve_imod_for_mod(self, mod2);
|
255
|
+
before_mod1 = retrieve_imod_before_mod(self, mod1);
|
256
|
+
before_mod2 = retrieve_imod_before_mod(self, mod2);
|
257
257
|
|
258
258
|
SWAP(RCLASS_SUPER(before_mod1), RCLASS_SUPER(before_mod2));
|
259
259
|
SWAP(RCLASS_SUPER(included_mod1), RCLASS_SUPER(included_mod2));
|
@@ -310,8 +310,8 @@ rb_uninclude(int argc, VALUE * argv, VALUE self)
|
|
310
310
|
if (!RTEST(rb_classmod_include_p(self, mod1)))
|
311
311
|
rb_raise(rb_eArgError, "Module not found");
|
312
312
|
|
313
|
-
VALUE before =
|
314
|
-
VALUE included_mod =
|
313
|
+
VALUE before = retrieve_imod_before_mod(self, mod1);
|
314
|
+
VALUE included_mod = retrieve_imod_for_mod(self, mod1);
|
315
315
|
|
316
316
|
if (mod1 == rb_cObject) rb_raise(rb_eRuntimeError, "can't delete Object");
|
317
317
|
|
@@ -333,7 +333,7 @@ rb_replace_module(VALUE self, VALUE mod1, VALUE mod2)
|
|
333
333
|
if (rb_classmod_include_p(self, mod2))
|
334
334
|
return rb_swap_modules(self, mod1, mod2);
|
335
335
|
|
336
|
-
VALUE before =
|
336
|
+
VALUE before = retrieve_imod_before_mod(self, mod1);
|
337
337
|
rb_uninclude(1, &mod1, self);
|
338
338
|
rb_include_module(before, mod2);
|
339
339
|
return self;
|
data/lib/1.8/remix.so
CHANGED
Binary file
|
data/lib/1.9/remix.so
CHANGED
Binary file
|
data/lib/remix/version.rb
CHANGED
data/lib/remix.rb
CHANGED
@@ -29,6 +29,40 @@ end
|
|
29
29
|
|
30
30
|
module Remix::ObjectExtensions
|
31
31
|
|
32
|
+
# Temporarily extends a module for the duration of a block.
|
33
|
+
# Module will be unextended at end of block.
|
34
|
+
# @param [Module] mod Module to be temporarily extended
|
35
|
+
def temp_extend(mod, &block)
|
36
|
+
begin
|
37
|
+
extend(mod)
|
38
|
+
yield
|
39
|
+
ensure
|
40
|
+
unextend(mod, true)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Temporarily extends a module for the duration of a block in a
|
45
|
+
# thread-safe manner.
|
46
|
+
# Module will be unextended at end of block.
|
47
|
+
# @param [Module] mod Module to be temporarily extended
|
48
|
+
def temp_extend_safe(mod, &block)
|
49
|
+
safe_code = proc do
|
50
|
+
begin
|
51
|
+
extend(mod)
|
52
|
+
yield
|
53
|
+
ensure
|
54
|
+
unextend(mod, true)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
if !Thread.current[:__exclusive__]
|
59
|
+
Thread.exclusive { Thread.current[:__exclusive__] = true; safe_code.call }
|
60
|
+
Thread.current[:__exclusive__] = false
|
61
|
+
else
|
62
|
+
safe_code.call
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
32
66
|
# Like `include_at()` but for the singleton class
|
33
67
|
# @see Remix::ModuleExtensions#include_at
|
34
68
|
def extend_at(index, mod)
|
@@ -87,6 +121,44 @@ module Remix::ObjectExtensions
|
|
87
121
|
end
|
88
122
|
end
|
89
123
|
|
124
|
+
module Remix::ModuleExtensions
|
125
|
+
|
126
|
+
# Temporarily includes a module for the duration of a block.
|
127
|
+
# Module will be unincluded at end of block.
|
128
|
+
# @param [Module] mod Module to be temporarily included
|
129
|
+
def temp_include(mod, &block)
|
130
|
+
begin
|
131
|
+
include(mod)
|
132
|
+
yield
|
133
|
+
ensure
|
134
|
+
uninclude(mod, true)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Temporarily includes a module for the duration of a block in a
|
139
|
+
# thread-safe manner.
|
140
|
+
# Module will be unincluded at end of block.
|
141
|
+
# @param [Module] mod Module to be temporarily included
|
142
|
+
def temp_include_safe(mod, &block)
|
143
|
+
safe_code = proc do
|
144
|
+
begin
|
145
|
+
include(mod)
|
146
|
+
yield
|
147
|
+
ensure
|
148
|
+
uninclude(mod, true)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
if !Thread.current[:__exclusive__]
|
153
|
+
Thread.exclusive { Thread.current[:__exclusive__] = true; safe_code.call }
|
154
|
+
Thread.current[:__exclusive__] = false
|
155
|
+
else
|
156
|
+
safe_code.call
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
|
90
162
|
# bring extend-based methods into Object
|
91
163
|
class Object
|
92
164
|
include Remix::ObjectExtensions
|
data/test/test.rb
CHANGED
@@ -8,12 +8,13 @@ class Module
|
|
8
8
|
end
|
9
9
|
|
10
10
|
puts "testing Remix version #{Remix::VERSION}..."
|
11
|
+
puts "Ruby version: #{RUBY_VERSION}"
|
11
12
|
|
12
13
|
describe 'Test basic remix functionality' do
|
13
14
|
before do
|
14
|
-
A = Module.new
|
15
|
+
A = Module.new { def hello; :hello; end }
|
15
16
|
B = Module.new
|
16
|
-
C = Module.new
|
17
|
+
C = Module.new
|
17
18
|
J = Module.new
|
18
19
|
|
19
20
|
M = Module.new
|
@@ -45,6 +46,26 @@ describe 'Test basic remix functionality' do
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
49
|
+
describe 'temp_extend' do
|
50
|
+
it 'should temporarily extend the module for the duration of a block' do
|
51
|
+
lambda { B.hello }.should.raise NoMethodError
|
52
|
+
B.temp_extend(A) do
|
53
|
+
B.hello.should == :hello
|
54
|
+
end
|
55
|
+
lambda { B.hello }.should.raise NoMethodError
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'temp_extend_safe' do
|
60
|
+
it 'should temporarily extend the module for the duration of a block in a threadsafe manner' do
|
61
|
+
lambda { B.hello }.should.raise NoMethodError
|
62
|
+
B.temp_extend_safe(A) do
|
63
|
+
B.hello.should == :hello
|
64
|
+
end
|
65
|
+
lambda { B.hello }.should.raise NoMethodError
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
48
69
|
describe 'unextend' do
|
49
70
|
it 'should unextend the module' do
|
50
71
|
C.include A, B
|
@@ -89,6 +110,26 @@ describe 'Test basic remix functionality' do
|
|
89
110
|
end
|
90
111
|
end
|
91
112
|
|
113
|
+
describe 'temp_include' do
|
114
|
+
it 'should temporarily include the module for the duration of a block' do
|
115
|
+
lambda { "john".hello }.should.raise NoMethodError
|
116
|
+
String.temp_include(A) do
|
117
|
+
"john".hello.should == :hello
|
118
|
+
end
|
119
|
+
lambda { "john".hello }.should.raise NoMethodError
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'temp_include_safe' do
|
124
|
+
it 'should temporarily include the module for the duration of a block in a threadsafe manner' do
|
125
|
+
lambda { "john".hello }.should.raise NoMethodError
|
126
|
+
String.temp_include_safe(A) do
|
127
|
+
"john".hello.should == :hello
|
128
|
+
end
|
129
|
+
lambda { "john".hello }.should.raise NoMethodError
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
92
133
|
describe 'include_before' do
|
93
134
|
it 'should insert module into correct position' do
|
94
135
|
M.include_before B, C
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
- 3
|
8
8
|
- 4
|
9
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
10
11
|
platform: i386-mingw32
|
11
12
|
authors:
|
12
13
|
- John Mair (banisterfiend)
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-11 00:00:00 +13:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -54,6 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
55
|
requirements:
|
55
56
|
- - ">="
|
56
57
|
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
57
59
|
segments:
|
58
60
|
- 0
|
59
61
|
version: "0"
|
@@ -62,6 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
64
|
requirements:
|
63
65
|
- - ">="
|
64
66
|
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
65
68
|
segments:
|
66
69
|
- 0
|
67
70
|
version: "0"
|