remix 0.1.0-i386-mingw32 → 0.2.0-i386-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,2 +1,4 @@
1
+ 26/10/2010 version 0.2.0
2
+ * added include_at_top, replace_module, module_move_up, etc
1
3
  25/10/2010 version 0.1.0
2
4
  * release!
data/README.markdown CHANGED
@@ -4,18 +4,25 @@ Remix
4
4
  (c) John Mair (banisterfiend)
5
5
  MIT license
6
6
 
7
- Makes inheritance chains read/write
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/ext/remix/remix.c CHANGED
@@ -1,16 +1,17 @@
1
- /* object2module.c */
2
- /* (C) John Mair 2009
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) == Qnil) {
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 != Qnil && m != rb_cObject) {
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 (get_source_module(RCLASS_SUPER(m)) != before)
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 != Qnil && m != rb_cObject) {
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
- rb_include_after(VALUE self, VALUE after, VALUE mod)
136
+ rb_module_move_up(VALUE self, VALUE mod)
135
137
  {
136
138
  rb_prepare_for_remix(self);
137
139
 
138
- VALUE k, m = self;
140
+ if (self == mod)
141
+ return self;
139
142
 
140
- k = get_source_module(m);
141
- while(k != after && m != Qnil && m != rb_cObject) {
142
- m = RCLASS_SUPER(m);
143
- k = get_source_module(m);
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
- if (k != after)
147
- rb_raise(rb_eRuntimeError, "'after' module not found");
149
+ return self;
150
+ }
148
151
 
149
- rb_include_module(m, mod);
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
- rb_include_before(VALUE self, VALUE before, VALUE mod)
170
+ rb_include_at_top(VALUE self, VALUE mod)
156
171
  {
157
172
  rb_prepare_for_remix(self);
158
173
 
159
- VALUE k, m = self;
160
-
161
- k = get_source_module(RCLASS_SUPER(m));
162
- while(k != before && m != Qnil && m != rb_cObject) {
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
- if (get_source_module(RCLASS_SUPER(m)) != before)
168
- rb_raise(rb_eRuntimeError, "'before' module not found");
179
+ return self;
180
+ }
169
181
 
170
- rb_include_module(m, mod);
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) != Qnil && RCLASS_SUPER(m) != rb_cObject)
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/1.8/remix.so CHANGED
Binary file
data/lib/1.9/remix.so CHANGED
Binary file
data/lib/remix/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Remix
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remix
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: i386-mingw32
12
12
  authors:
13
13
  - John Mair (banisterfiend)
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-25 00:00:00 +13:00
18
+ date: 2010-10-26 00:00:00 +13:00
19
19
  default_executable:
20
20
  dependencies: []
21
21