remix 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/README.markdown +15 -1
- data/Rakefile +2 -2
- data/ext/remix/remix.c +74 -31
- data/lib/remix/version.rb +1 -1
- metadata +4 -4
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -4,18 +4,25 @@ Remix
|
|
4
4
|
(c) John Mair (banisterfiend)
|
5
5
|
MIT license
|
6
6
|
|
7
|
-
|
7
|
+
Ruby modules re-mixed and remastered
|
8
8
|
|
9
9
|
** This is BETA software and has not yet been thoroughly tested, use
|
10
10
|
at own risk **
|
11
|
+
|
12
|
+
install the gem: **for testing purposes only**
|
13
|
+
`gem install remix`
|
11
14
|
|
12
15
|
Currently supports:
|
13
16
|
|
14
17
|
* include_at(index)
|
18
|
+
* include_at_top(Mod)
|
15
19
|
* include_before(BeforeMod, Mod)
|
16
20
|
* include_after(AfterMod, Mod)
|
17
21
|
* swap_modules(Mod1, Mod2)
|
18
22
|
* remove_module(Mod)
|
23
|
+
* module_move_up(Mod)
|
24
|
+
* module_move_down(Mod)
|
25
|
+
* replace_module(Mod1, Mod2)
|
19
26
|
* ...more to come!
|
20
27
|
|
21
28
|
example:
|
@@ -29,12 +36,19 @@ example:
|
|
29
36
|
end
|
30
37
|
|
31
38
|
B.ancestors #=> [B, A, M, ...]
|
39
|
+
|
32
40
|
B.swap_modules A, M
|
41
|
+
|
33
42
|
B.ancestors #=> [B, M, A, ...]
|
43
|
+
|
34
44
|
module J end
|
45
|
+
|
35
46
|
B.include_before A, J
|
47
|
+
|
36
48
|
B.ancestors #=> [B, M, J, A, ...]
|
49
|
+
|
37
50
|
B.remove_module M
|
51
|
+
|
38
52
|
B.ancestors #=> [B, J, A, ...]
|
39
53
|
|
40
54
|
|
data/Rakefile
CHANGED
@@ -20,14 +20,14 @@ specification = Gem::Specification.new do |s|
|
|
20
20
|
s.description = s.summary
|
21
21
|
s.require_path = 'lib'
|
22
22
|
s.platform = Gem::Platform::RUBY
|
23
|
-
#s.platform = 'i386-
|
23
|
+
#s.platform = 'i386-mingw32'
|
24
24
|
s.homepage = "http://banisterfiend.wordpress.com"
|
25
25
|
s.has_rdoc = 'yard'
|
26
26
|
|
27
27
|
s.extensions = ["ext/remix/extconf.rb"]
|
28
28
|
s.files = ["Rakefile", "README.markdown", "CHANGELOG",
|
29
29
|
"lib/remix.rb", "lib/remix/version.rb"] +
|
30
|
-
# ["lib/1.9/
|
30
|
+
# ["lib/1.9/remix.so", "lib/1.8/remix.so"] +
|
31
31
|
FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
|
32
32
|
end
|
33
33
|
|
data/ext/remix/remix.c
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
-
/*
|
2
|
-
/* (C) John Mair
|
1
|
+
/* remix.c */
|
2
|
+
/* (C) John Mair 2010
|
3
3
|
* This program is distributed under the terms of the MIT License
|
4
4
|
* */
|
5
5
|
|
6
6
|
#include <ruby.h>
|
7
7
|
#include "compat.h"
|
8
8
|
|
9
|
+
VALUE rb_swap_modules(VALUE self, VALUE mod1, VALUE mod2);
|
10
|
+
|
9
11
|
/* a modified version of include_class_new from class.c */
|
10
12
|
static VALUE
|
11
13
|
j_class_new(VALUE module, VALUE sup)
|
12
14
|
{
|
13
|
-
|
14
15
|
VALUE klass = create_class(T_ICLASS, rb_cClass);
|
15
16
|
|
16
17
|
if (TYPE(module) == T_ICLASS) {
|
@@ -39,8 +40,6 @@ j_class_new(VALUE module, VALUE sup)
|
|
39
40
|
RCLASS_M_TBL(klass) = RCLASS_M_TBL(CLASS_OF(module));
|
40
41
|
}
|
41
42
|
|
42
|
-
/* */
|
43
|
-
|
44
43
|
if (TYPE(module) == T_ICLASS) {
|
45
44
|
KLASS_OF(klass) = rb_iv_get(klass, "__module__");
|
46
45
|
}
|
@@ -59,7 +58,7 @@ j_class_new(VALUE module, VALUE sup)
|
|
59
58
|
static VALUE
|
60
59
|
set_supers(VALUE c)
|
61
60
|
{
|
62
|
-
if (RCLASS_SUPER(c) == rb_cObject || RCLASS_SUPER(c) ==
|
61
|
+
if (RCLASS_SUPER(c) == rb_cObject || RCLASS_SUPER(c) == 0) {
|
63
62
|
return RCLASS_SUPER(c);
|
64
63
|
}
|
65
64
|
else {
|
@@ -83,6 +82,9 @@ inline static VALUE
|
|
83
82
|
get_source_module(VALUE mod)
|
84
83
|
{
|
85
84
|
switch (TYPE(mod)) {
|
85
|
+
case T_FALSE:
|
86
|
+
return Qfalse;
|
87
|
+
break;
|
86
88
|
case T_ICLASS:
|
87
89
|
if (RTEST(rb_iv_get(mod, "__module__")))
|
88
90
|
return rb_iv_get(mod, "__module__");
|
@@ -105,11 +107,11 @@ static VALUE
|
|
105
107
|
retrieve_before_mod(VALUE m, VALUE before)
|
106
108
|
{
|
107
109
|
VALUE k = get_source_module(RCLASS_SUPER(m));
|
108
|
-
while(k != before && m !=
|
110
|
+
while(k != before && m != 0 && m != rb_cObject) {
|
109
111
|
m = RCLASS_SUPER(m);
|
110
112
|
k = get_source_module(RCLASS_SUPER(m));
|
111
113
|
}
|
112
|
-
if (
|
114
|
+
if (k != before)
|
113
115
|
rb_raise(rb_eRuntimeError, "'before' module not found");
|
114
116
|
|
115
117
|
return m;
|
@@ -119,7 +121,7 @@ static VALUE
|
|
119
121
|
retrieve_mod(VALUE m, VALUE after)
|
120
122
|
{
|
121
123
|
VALUE k = get_source_module(m);
|
122
|
-
while(k != after && m !=
|
124
|
+
while(k != after && m != 0 && m != rb_cObject) {
|
123
125
|
m = RCLASS_SUPER(m);
|
124
126
|
k = get_source_module(m);
|
125
127
|
}
|
@@ -131,44 +133,65 @@ retrieve_mod(VALUE m, VALUE after)
|
|
131
133
|
}
|
132
134
|
|
133
135
|
VALUE
|
134
|
-
|
136
|
+
rb_module_move_up(VALUE self, VALUE mod)
|
135
137
|
{
|
136
138
|
rb_prepare_for_remix(self);
|
137
139
|
|
138
|
-
|
140
|
+
if (self == mod)
|
141
|
+
return self;
|
139
142
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
143
|
+
VALUE included_mod = retrieve_mod(self, mod);
|
144
|
+
if (RCLASS_SUPER(included_mod) == rb_cObject || RCLASS_SUPER(included_mod) == 0)
|
145
|
+
return self;
|
146
|
+
|
147
|
+
rb_swap_modules(self, mod, get_source_module(RCLASS_SUPER(included_mod)));
|
145
148
|
|
146
|
-
|
147
|
-
|
149
|
+
return self;
|
150
|
+
}
|
148
151
|
|
149
|
-
|
152
|
+
VALUE
|
153
|
+
rb_module_move_down(VALUE self, VALUE mod)
|
154
|
+
{
|
155
|
+
rb_prepare_for_remix(self);
|
156
|
+
|
157
|
+
if (self == mod)
|
158
|
+
return self;
|
159
|
+
|
160
|
+
VALUE before_included_mod = retrieve_before_mod(self, mod);
|
161
|
+
if (before_included_mod == self)
|
162
|
+
return self;
|
163
|
+
|
164
|
+
rb_swap_modules(self, mod, get_source_module(before_included_mod));
|
150
165
|
|
151
166
|
return self;
|
152
167
|
}
|
153
168
|
|
154
169
|
VALUE
|
155
|
-
|
170
|
+
rb_include_at_top(VALUE self, VALUE mod)
|
156
171
|
{
|
157
172
|
rb_prepare_for_remix(self);
|
158
173
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
m = RCLASS_SUPER(m);
|
164
|
-
k = get_source_module(RCLASS_SUPER(m));
|
165
|
-
}
|
174
|
+
if (TYPE(self) == T_MODULE)
|
175
|
+
rb_include_module(retrieve_before_mod(self, Qfalse), mod);
|
176
|
+
else
|
177
|
+
rb_include_module(retrieve_before_mod(self, rb_cObject), mod);
|
166
178
|
|
167
|
-
|
168
|
-
|
179
|
+
return self;
|
180
|
+
}
|
169
181
|
|
170
|
-
|
182
|
+
VALUE
|
183
|
+
rb_include_after(VALUE self, VALUE after, VALUE mod)
|
184
|
+
{
|
185
|
+
rb_prepare_for_remix(self);
|
186
|
+
rb_include_module(retrieve_mod(self, after), mod);
|
187
|
+
return self;
|
188
|
+
}
|
171
189
|
|
190
|
+
VALUE
|
191
|
+
rb_include_before(VALUE self, VALUE before, VALUE mod)
|
192
|
+
{
|
193
|
+
rb_prepare_for_remix(self);
|
194
|
+
rb_include_module(retrieve_before_mod(self, before), mod);
|
172
195
|
return self;
|
173
196
|
}
|
174
197
|
|
@@ -181,7 +204,7 @@ rb_include_at(VALUE self, VALUE mod, VALUE rb_index)
|
|
181
204
|
VALUE m = self;
|
182
205
|
|
183
206
|
int i = 0;
|
184
|
-
while(i++ < index && RCLASS_SUPER(m) !=
|
207
|
+
while(i++ < index && RCLASS_SUPER(m) != 0 && RCLASS_SUPER(m) != rb_cObject)
|
185
208
|
m = RCLASS_SUPER(m);
|
186
209
|
|
187
210
|
rb_include_module(m, mod);
|
@@ -228,14 +251,34 @@ rb_remove_module(VALUE self, VALUE mod1)
|
|
228
251
|
return self;
|
229
252
|
}
|
230
253
|
|
254
|
+
VALUE
|
255
|
+
rb_replace_module(VALUE self, VALUE mod1, VALUE mod2)
|
256
|
+
{
|
257
|
+
rb_prepare_for_remix(self);
|
258
|
+
|
259
|
+
if (rb_mod_include_p(self, mod2))
|
260
|
+
return rb_swap_modules(self, mod1, mod2);
|
261
|
+
|
262
|
+
VALUE before = retrieve_before_mod(self, mod1);
|
263
|
+
rb_remove_module(self, mod1);
|
264
|
+
rb_include_module(before, mod2);
|
265
|
+
return self;
|
266
|
+
}
|
267
|
+
|
231
268
|
void
|
232
269
|
Init_remix()
|
233
270
|
{
|
234
271
|
rb_define_method(rb_cObject, "ready_remix", rb_prepare_for_remix, 0);
|
272
|
+
rb_define_method(rb_cModule, "module_move_up", rb_module_move_up, 1);
|
273
|
+
rb_define_method(rb_cModule, "module_move_down", rb_module_move_down, 1);
|
274
|
+
|
235
275
|
rb_define_method(rb_cModule, "include_at", rb_include_at, 2);
|
236
276
|
rb_define_method(rb_cModule, "include_before", rb_include_before, 2);
|
237
277
|
rb_define_method(rb_cModule, "include_after", rb_include_after, 2);
|
278
|
+
rb_define_method(rb_cModule, "include_at_top", rb_include_at_top, 1);
|
279
|
+
|
238
280
|
rb_define_method(rb_cModule, "swap_modules", rb_swap_modules, 2);
|
239
281
|
rb_define_method(rb_cModule, "remove_module", rb_remove_module, 1);
|
282
|
+
rb_define_method(rb_cModule, "replace_module", rb_replace_module, 2);
|
240
283
|
}
|
241
284
|
|
data/lib/remix/version.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- John Mair (banisterfiend)
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-26 00:00:00 +13:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -35,7 +35,7 @@ files:
|
|
35
35
|
- ext/remix/extconf.rb
|
36
36
|
- ext/remix/compat.h
|
37
37
|
- ext/remix/remix.c
|
38
|
-
has_rdoc:
|
38
|
+
has_rdoc: yard
|
39
39
|
homepage: http://banisterfiend.wordpress.com
|
40
40
|
licenses: []
|
41
41
|
|