mixology 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +40 -12
- data/ext/mixology/extconf.rb +1 -0
- data/ext/mixology/mixology.c +111 -64
- data/lib/mixology_rubinius.rb +39 -0
- data/test/mixology_test.rb +43 -30
- data/test/test_helper.rb +6 -16
- metadata +42 -35
- data/ext/mixology/rbconfig.rb +0 -169
data/Rakefile
CHANGED
@@ -3,18 +3,19 @@ require 'rake/clean'
|
|
3
3
|
require 'rake/gempackagetask'
|
4
4
|
require "rake/testtask"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
else
|
9
|
-
task :default => %w[clean compile test]
|
10
|
-
end
|
6
|
+
desc "clean, compile, test"
|
7
|
+
task :default => %w[clean compile test]
|
11
8
|
|
12
9
|
Rake::TestTask.new("test") do |t|
|
13
10
|
t.pattern = "test/**/*_test.rb"
|
14
11
|
end
|
15
12
|
|
16
13
|
desc "Builds the extension"
|
17
|
-
|
14
|
+
if RUBY_PLATFORM =~ /java/
|
15
|
+
task :compile => :compile_java
|
16
|
+
else
|
17
|
+
task :compile => %W[ext/mixology/Makefile ext/mixology/mixology.#{Config::CONFIG['DLEXT']}]
|
18
|
+
end
|
18
19
|
|
19
20
|
file "ext/mixology/Makefile" => ["ext/mixology/extconf.rb"] do
|
20
21
|
Dir.chdir("ext/mixology") do
|
@@ -29,15 +30,13 @@ file "ext/mixology/mixology.#{Config::CONFIG['DLEXT']}" do
|
|
29
30
|
cp "ext/mixology/mixology.#{Config::CONFIG['DLEXT']}", "lib"
|
30
31
|
end
|
31
32
|
|
32
|
-
CLEAN.include %w[ext/mixology/Makefile ext/mixology/mixology.bundle lib/mixology.bundle]
|
33
|
+
CLEAN.include %w[ext/mixology/Makefile ext/mixology/mixology.bundle ext/mixology/mixology.so lib/mixology.bundle lib/mixology.so ext/mixology/mixology.o]
|
33
34
|
CLEAN.include %w[ext/mixology/MixableService.class ext/mixology/mixable.jar lib/mixology.jar]
|
34
35
|
|
35
|
-
Gem::manage_gems
|
36
|
-
|
37
36
|
specification = Gem::Specification.new do |s|
|
38
37
|
s.name = "mixology"
|
39
38
|
s.summary = "Mixology enables objects to mixin and unmix modules."
|
40
|
-
s.version = "0.
|
39
|
+
s.version = "0.2.0"
|
41
40
|
s.author = "anonymous z, Pat Farley, Dan Manges"
|
42
41
|
s.description = s.summary
|
43
42
|
s.homepage = "http://mixology.rubyforge.org"
|
@@ -49,7 +48,7 @@ specification = Gem::Specification.new do |s|
|
|
49
48
|
s.platform = Gem::Platform::WIN32
|
50
49
|
s.files += ["lib/mixology.so"]
|
51
50
|
elsif RUBY_PLATFORM =~ /java/
|
52
|
-
s.platform = "
|
51
|
+
s.platform = "java"
|
53
52
|
s.files += ["lib/mixology.jar"]
|
54
53
|
else
|
55
54
|
s.platform = Gem::Platform::RUBY
|
@@ -64,8 +63,37 @@ end
|
|
64
63
|
desc "Compiles the JRuby extension"
|
65
64
|
task :compile_java do
|
66
65
|
Dir.chdir("ext/mixology") do
|
67
|
-
sh %{javac -source 1.
|
66
|
+
sh %{javac -source 1.5 -target 1.5 -classpath $JRUBY_HOME/lib/jruby.jar MixologyService.java}
|
68
67
|
sh %{jar cf mixology.jar MixologyService.class}
|
69
68
|
cp "mixology.jar", "../../lib/mixology.jar"
|
70
69
|
end
|
71
70
|
end
|
71
|
+
|
72
|
+
desc "test against multiple ruby implementations"
|
73
|
+
task :test_multi do
|
74
|
+
# this is specific to how I have Ruby installed on my machine -Dan
|
75
|
+
jruby = %w[1.1.3 1.1.4]
|
76
|
+
mri = %w[1.8.6-p368 1.9.1-p129]
|
77
|
+
failed = false
|
78
|
+
test_implementation = proc do |implementation, command|
|
79
|
+
print "#{implementation}: "
|
80
|
+
output = `#{command} 2>&1`
|
81
|
+
if $?.success? && output =~ /\d\d+ tests.*0 failures, 0 errors/
|
82
|
+
puts "PASS"
|
83
|
+
else
|
84
|
+
puts "FAIL"
|
85
|
+
failed = true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
jruby.each do |jruby_version|
|
89
|
+
test_implementation.call(
|
90
|
+
"JRuby #{jruby_version}",
|
91
|
+
"JRUBY_HOME=/usr/local/jruby-#{jruby_version} /usr/local/jruby-#{jruby_version}/bin/jruby -S rake"
|
92
|
+
)
|
93
|
+
end
|
94
|
+
mri.each do |mri_version|
|
95
|
+
test_implementation.call "MRI #{mri_version}", "/usr/local/ruby-#{mri_version}/bin/rake"
|
96
|
+
end
|
97
|
+
fail if failed
|
98
|
+
end
|
99
|
+
|
data/ext/mixology/extconf.rb
CHANGED
data/ext/mixology/mixology.c
CHANGED
@@ -1,78 +1,125 @@
|
|
1
1
|
#include "ruby.h"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
/* cannot use ordinary CLASS_OF as it does not return an lvalue */
|
4
|
+
#define KLASS_OF(c) (RBASIC(c)->klass)
|
5
|
+
|
6
|
+
/* macros for backwards compatibility with 1.8 */
|
7
|
+
#ifndef RUBY_19
|
8
|
+
# define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
|
9
|
+
# define RCLASS_SUPER(c) (RCLASS(c)->super)
|
10
|
+
# define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
|
11
|
+
#endif
|
12
|
+
|
13
|
+
#ifdef RUBY_19
|
14
|
+
static VALUE class_alloc(VALUE flags, VALUE klass)
|
15
|
+
{
|
16
|
+
rb_classext_t *ext = ALLOC(rb_classext_t);
|
17
|
+
NEWOBJ(obj, struct RClass);
|
18
|
+
OBJSETUP(obj, klass, flags);
|
19
|
+
obj->ptr = ext;
|
20
|
+
RCLASS_IV_TBL(obj) = 0;
|
21
|
+
RCLASS_M_TBL(obj) = 0;
|
22
|
+
RCLASS_SUPER(obj) = 0;
|
23
|
+
RCLASS_IV_INDEX_TBL(obj) = 0;
|
24
|
+
return (VALUE)obj;
|
12
25
|
}
|
26
|
+
#endif
|
13
27
|
|
14
|
-
static
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
rb_clear_cache();
|
24
|
-
}
|
25
|
-
}
|
26
|
-
}
|
27
|
-
return self;
|
28
|
+
static void remove_nested_module(VALUE klass, VALUE include_class)
|
29
|
+
{
|
30
|
+
if (KLASS_OF(RCLASS_SUPER(klass)) != KLASS_OF(RCLASS_SUPER(include_class))) {
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
if (RCLASS_SUPER(RCLASS_SUPER(include_class)) && BUILTIN_TYPE(RCLASS_SUPER(include_class)) == T_ICLASS) {
|
34
|
+
remove_nested_module(RCLASS_SUPER(klass), RCLASS_SUPER(include_class));
|
35
|
+
}
|
36
|
+
RCLASS_SUPER(klass) = RCLASS_SUPER(RCLASS_SUPER(klass));
|
28
37
|
}
|
29
38
|
|
30
|
-
static
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
if (TYPE(module) == T_ICLASS) {
|
45
|
-
RBASIC(klass)->klass = RBASIC(module)->klass;
|
46
|
-
}
|
47
|
-
else {
|
48
|
-
RBASIC(klass)->klass = module;
|
49
|
-
}
|
50
|
-
OBJ_INFECT(klass, module);
|
51
|
-
OBJ_INFECT(klass, super);
|
52
|
-
|
53
|
-
RCLASS(rb_singleton_class(self))->super = (int)klass;
|
39
|
+
static VALUE rb_unmix(VALUE self, VALUE module)
|
40
|
+
{
|
41
|
+
VALUE klass;
|
42
|
+
|
43
|
+
/* check that module is valid */
|
44
|
+
if (TYPE(module) != T_MODULE)
|
45
|
+
rb_raise(rb_eArgError, "error: parameter must be a module");
|
46
|
+
|
47
|
+
for (klass = KLASS_OF(self); klass != rb_class_real(klass); klass = RCLASS_SUPER(klass)) {
|
48
|
+
VALUE super = RCLASS_SUPER(klass);
|
49
|
+
if (BUILTIN_TYPE(super) == T_ICLASS) {
|
50
|
+
if (KLASS_OF(super) == module) {
|
51
|
+
if (RCLASS_SUPER(module) && BUILTIN_TYPE(RCLASS_SUPER(module)) == T_ICLASS)
|
52
|
+
remove_nested_module(super, module);
|
54
53
|
|
54
|
+
RCLASS_SUPER(klass) = RCLASS_SUPER(RCLASS_SUPER(klass));
|
55
|
+
rb_clear_cache();
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
return self;
|
55
60
|
}
|
56
61
|
|
57
|
-
static
|
58
|
-
|
62
|
+
static void add_module(VALUE self, VALUE module)
|
63
|
+
{
|
64
|
+
VALUE super = RCLASS_SUPER(rb_singleton_class(self));
|
59
65
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
+
#ifdef RUBY_19
|
67
|
+
VALUE klass = class_alloc(T_ICLASS, rb_cClass);
|
68
|
+
#else
|
69
|
+
NEWOBJ(klass, struct RClass);
|
70
|
+
OBJSETUP(klass, rb_cClass, T_ICLASS);
|
71
|
+
#endif
|
66
72
|
|
67
|
-
|
73
|
+
if (BUILTIN_TYPE(module) == T_ICLASS) {
|
74
|
+
module = KLASS_OF(module);
|
75
|
+
}
|
76
|
+
if (!RCLASS_IV_TBL(module)) {
|
77
|
+
RCLASS_IV_TBL(module) = (void*)st_init_numtable();
|
78
|
+
}
|
68
79
|
|
69
|
-
|
70
|
-
|
80
|
+
RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
|
81
|
+
RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
|
82
|
+
RCLASS_SUPER(klass) = super;
|
83
|
+
|
84
|
+
if (TYPE(module) == T_ICLASS) {
|
85
|
+
KLASS_OF(klass) = KLASS_OF(module);
|
86
|
+
} else {
|
87
|
+
KLASS_OF(klass) = module;
|
88
|
+
}
|
89
|
+
OBJ_INFECT(klass, module);
|
90
|
+
OBJ_INFECT(klass, super);
|
91
|
+
|
92
|
+
RCLASS_SUPER(rb_singleton_class(self)) = (VALUE)klass;
|
71
93
|
}
|
72
94
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
95
|
+
static VALUE rb_mixin(VALUE self, VALUE module)
|
96
|
+
{
|
97
|
+
VALUE nested_modules;
|
98
|
+
int index;
|
99
|
+
|
100
|
+
/* check that module is valid */
|
101
|
+
if (TYPE(module) != T_MODULE)
|
102
|
+
rb_raise(rb_eArgError, "error: parameter must be a module");
|
103
|
+
|
104
|
+
rb_unmix(self, module);
|
105
|
+
nested_modules = rb_mod_included_modules(module);
|
106
|
+
|
107
|
+
for (index = RARRAY_LEN(nested_modules); index > 0; index--) {
|
108
|
+
VALUE nested_module = RARRAY_PTR(nested_modules)[index - 1];
|
109
|
+
add_module(self, nested_module);
|
110
|
+
}
|
111
|
+
|
112
|
+
add_module(self, module);
|
113
|
+
|
114
|
+
rb_clear_cache();
|
115
|
+
return self;
|
116
|
+
}
|
117
|
+
|
118
|
+
void Init_mixology()
|
119
|
+
{
|
120
|
+
VALUE Mixology = rb_define_module("Mixology");
|
121
|
+
|
122
|
+
rb_define_method(Mixology, "mixin", rb_mixin, 1);
|
123
|
+
rb_define_method(Mixology, "unmix", rb_unmix, 1);
|
124
|
+
rb_include_module(rb_cObject, Mixology);
|
125
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Mixology
|
2
|
+
def mixin(mod)
|
3
|
+
unmix mod
|
4
|
+
reset_method_cache
|
5
|
+
IncludedModule.new(mod).attach_to metaclass
|
6
|
+
reset_method_cache
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def unmix(mod_to_unmix)
|
11
|
+
last_super = metaclass
|
12
|
+
this_super = metaclass.direct_superclass
|
13
|
+
while this_super
|
14
|
+
break if this_super == self.class
|
15
|
+
if (this_super == mod_to_unmix ||
|
16
|
+
this_super.respond_to?(:module) && this_super.module == mod_to_unmix)
|
17
|
+
reset_method_cache
|
18
|
+
last_super.superclass = this_super.direct_superclass
|
19
|
+
reset_method_cache
|
20
|
+
return self
|
21
|
+
else
|
22
|
+
last_super = this_super
|
23
|
+
this_super = this_super.direct_superclass
|
24
|
+
end
|
25
|
+
end
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def reset_method_cache
|
32
|
+
self.methods.each do |name|
|
33
|
+
name = self.metaclass.send(:normalize_name,name)
|
34
|
+
Rubinius::VM.reset_method_cache(name)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Object.send :include, Mixology
|
data/test/mixology_test.rb
CHANGED
@@ -2,14 +2,14 @@ require File.dirname(__FILE__) + "/test_helper"
|
|
2
2
|
|
3
3
|
class MixologyTest < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
5
|
+
def test_mixin
|
6
6
|
mixin = Module.new { def foo; "foo"; end }
|
7
7
|
object = Object.new
|
8
8
|
object.mixin mixin
|
9
9
|
assert_equal "foo", object.foo
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
def test_unmix
|
13
13
|
mixin = Module.new { def foo; "mixin"; end }
|
14
14
|
object = Class.new { def foo; "object"; end }.new
|
15
15
|
object.mixin mixin
|
@@ -18,7 +18,7 @@ class MixologyTest < Test::Unit::TestCase
|
|
18
18
|
assert_equal "object", object.foo
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
def test_mixin_twice
|
22
22
|
first_mixin = Module.new { def foo; "first"; end }
|
23
23
|
second_mixin = Module.new { def foo; "second"; end }
|
24
24
|
object = Object.new
|
@@ -27,13 +27,13 @@ class MixologyTest < Test::Unit::TestCase
|
|
27
27
|
assert_equal "second", object.foo
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
def test_mixin_to_class
|
31
31
|
mix = Module.new { def foo; "foo"; end }
|
32
32
|
klass = Class.new { mixin mix }
|
33
33
|
assert_equal "foo", klass.foo
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
def test_can_mixin_again
|
37
37
|
first_mixin = Module.new { def foo; "first"; end }
|
38
38
|
second_mixin = Module.new { def foo; "second"; end }
|
39
39
|
object = Object.new
|
@@ -43,7 +43,7 @@ class MixologyTest < Test::Unit::TestCase
|
|
43
43
|
assert_equal "first", object.foo
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
def test_unmix_effects_limited_to_instance
|
47
47
|
mixin = Module.new { def foo; "mixin"; end }
|
48
48
|
object = Class.new {include mixin}.new
|
49
49
|
assert_equal "mixin", object.foo
|
@@ -51,7 +51,7 @@ class MixologyTest < Test::Unit::TestCase
|
|
51
51
|
assert_equal "mixin", object.foo
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
def test_can_add_mod_to_an_instance_even_when_already_included_by_class
|
55
55
|
mixin = Module.new { def foo; "mixin"; end }
|
56
56
|
klass = Class.new {include mixin; def foo; "class"; end }
|
57
57
|
object = klass.new
|
@@ -60,92 +60,101 @@ class MixologyTest < Test::Unit::TestCase
|
|
60
60
|
assert_equal "mixin", object.foo
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
def test_included_modules_after_mixin
|
64
64
|
mixin = Module.new
|
65
65
|
object = Object.new
|
66
66
|
object.mixin mixin
|
67
|
-
assert_equal [mixin, Mixology, Kernel], (class << object; self; end).included_modules
|
67
|
+
assert_equal [mixin, Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
def test_included_modules_after_unmix
|
71
71
|
mixin = Module.new
|
72
72
|
object = Object.new
|
73
73
|
object.mixin mixin
|
74
74
|
object.unmix mixin
|
75
|
-
assert_equal [Mixology, Kernel], (class << object; self; end).included_modules
|
75
|
+
assert_equal [Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
76
76
|
end
|
77
77
|
|
78
|
-
|
78
|
+
def test_included_modules_after_remix
|
79
79
|
mixin_one = Module.new
|
80
80
|
mixin_two = Module.new
|
81
81
|
object = Object.new
|
82
82
|
object.mixin mixin_one
|
83
83
|
object.mixin mixin_two
|
84
|
-
assert_equal [mixin_two, mixin_one, Mixology, Kernel], (class << object; self; end).included_modules
|
84
|
+
assert_equal [mixin_two, mixin_one, Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
85
85
|
object.mixin mixin_one
|
86
|
-
assert_equal [mixin_one, mixin_two, Mixology, Kernel], (class << object; self; end).included_modules
|
86
|
+
assert_equal [mixin_one, mixin_two, Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
87
87
|
end
|
88
88
|
|
89
|
-
|
89
|
+
def test_mixin_returns_object
|
90
90
|
object = Object.new
|
91
91
|
mixin = Module.new
|
92
92
|
assert_equal object, object.mixin(mixin)
|
93
93
|
end
|
94
94
|
|
95
|
-
|
95
|
+
def test_unmix_returns_object
|
96
96
|
object = Object.new
|
97
97
|
mixin = Module.new
|
98
98
|
object.mixin mixin
|
99
99
|
assert_equal object, object.unmix(mixin)
|
100
100
|
end
|
101
101
|
|
102
|
-
|
102
|
+
def test_nested_modules_are_mixedin
|
103
|
+
if rubinius?
|
104
|
+
print "PENDING"; return
|
105
|
+
end
|
103
106
|
nested_module = Module.new { def foo; "foo"; end }
|
104
107
|
mixin = Module.new { include nested_module }
|
105
108
|
object = Object.new
|
106
109
|
object.mixin mixin
|
107
|
-
assert_equal [mixin, nested_module, Mixology, Kernel], (class << object; self; end).included_modules
|
110
|
+
assert_equal [mixin, nested_module, Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
108
111
|
end
|
109
112
|
|
110
|
-
|
113
|
+
def test_nested_modules_are_mixedin_deeply
|
114
|
+
if rubinius?
|
115
|
+
print "PENDING"; return
|
116
|
+
end
|
111
117
|
nested_module_ultimate = Module.new
|
112
118
|
nested_module_penultimate = Module.new { include nested_module_ultimate }
|
113
119
|
nested_module = Module.new { include nested_module_penultimate }
|
114
120
|
mixin = Module.new { include nested_module }
|
115
121
|
object = Object.new
|
116
122
|
object.mixin mixin
|
117
|
-
assert_equal [mixin, nested_module, nested_module_penultimate, nested_module_ultimate, Mixology, Kernel], (class << object; self; end).included_modules
|
123
|
+
assert_equal [mixin, nested_module, nested_module_penultimate, nested_module_ultimate, Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
118
124
|
end
|
119
125
|
|
120
|
-
|
126
|
+
def test_nested_modules_are_mixedin_even_if_already_mixed_in
|
127
|
+
if rubinius?
|
128
|
+
print "PENDING"; return
|
129
|
+
end
|
121
130
|
nested_module = Module.new { def foo; "foo"; end }
|
122
131
|
mixin = Module.new { include nested_module }
|
123
132
|
object = Object.new
|
124
133
|
object.mixin nested_module
|
125
134
|
object.mixin mixin
|
126
|
-
assert_equal [mixin, nested_module, nested_module, Mixology, Kernel], (class << object; self; end).included_modules
|
135
|
+
assert_equal [mixin, nested_module, nested_module, Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
127
136
|
end
|
128
137
|
|
129
|
-
|
138
|
+
def test_module_is_not_unmixed_if_it_is_outside_nested_chain
|
130
139
|
nested_module = Module.new
|
131
140
|
mixin = Module.new { include nested_module }
|
132
141
|
object = Object.new
|
133
142
|
object.mixin nested_module
|
134
143
|
object.mixin mixin
|
135
144
|
object.unmix mixin
|
136
|
-
assert_equal [nested_module, Mixology, Kernel], (class << object; self; end).included_modules
|
145
|
+
assert_equal [nested_module, Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
137
146
|
end
|
138
147
|
|
139
|
-
|
148
|
+
def test_nested_modules_are_unmixed
|
140
149
|
nested_module = Module.new
|
141
150
|
mixin = Module.new { include nested_module }
|
142
151
|
object = Object.new
|
143
152
|
object.mixin mixin
|
144
153
|
object.unmix mixin
|
145
|
-
assert_equal [Mixology, Kernel], (class << object; self; end).included_modules
|
154
|
+
assert_equal [Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
146
155
|
end
|
147
156
|
|
148
|
-
|
157
|
+
def test_nested_modules_are_unmixed_deeply
|
149
158
|
nested_module_ultimate = Module.new
|
150
159
|
nested_module_penultimate = Module.new { include nested_module_ultimate }
|
151
160
|
nested_module = Module.new { include nested_module_penultimate }
|
@@ -153,10 +162,10 @@ class MixologyTest < Test::Unit::TestCase
|
|
153
162
|
object = Object.new
|
154
163
|
object.mixin mixin
|
155
164
|
object.unmix mixin
|
156
|
-
assert_equal [Mixology, Kernel], (class << object; self; end).included_modules
|
165
|
+
assert_equal [Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
157
166
|
end
|
158
167
|
|
159
|
-
|
168
|
+
def test_unrelated_modules_are_not_unmixed
|
160
169
|
unrelated = Module.new
|
161
170
|
nested_module = Module.new
|
162
171
|
mixin = Module.new { include nested_module }
|
@@ -164,7 +173,11 @@ class MixologyTest < Test::Unit::TestCase
|
|
164
173
|
object.mixin unrelated
|
165
174
|
object.mixin mixin
|
166
175
|
object.unmix mixin
|
167
|
-
assert_equal [unrelated, Mixology, Kernel], (class << object; self; end).included_modules
|
176
|
+
assert_equal [unrelated, Mixology, PP::ObjectMixin, Kernel], (class << object; self; end).included_modules
|
177
|
+
end
|
178
|
+
|
179
|
+
def rubinius?
|
180
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
|
168
181
|
end
|
169
182
|
|
170
183
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,20 +1,10 @@
|
|
1
1
|
require "test/unit"
|
2
|
-
require
|
2
|
+
# In Ruby 1.9, require test/unit will implicitly require pp, we do it here explicitly to ensure compatibily.
|
3
|
+
require "pp"
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
define_method("test_#{test_name}", &block)
|
8
|
-
end
|
9
|
-
end
|
5
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
|
6
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
|
7
|
+
require "mixology_rubinius"
|
10
8
|
else
|
11
|
-
|
12
|
-
gem "dust"
|
13
|
-
require "dust"
|
14
|
-
rescue LoadError
|
15
|
-
raise "To run the tests, 'gem install dust'"
|
16
|
-
end
|
9
|
+
require "mixology"
|
17
10
|
end
|
18
|
-
|
19
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
|
20
|
-
require "mixology"
|
metadata
CHANGED
@@ -1,51 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.3
|
3
|
-
specification_version: 1
|
4
2
|
name: mixology
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-08-31 00:00:00 -04:00
|
8
|
-
summary: Mixology enables objects to mixin and unmix modules.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email:
|
12
|
-
homepage: http://mixology.rubyforge.org
|
13
|
-
rubyforge_project: mixology
|
14
|
-
description: Mixology enables objects to mixin and unmix modules.
|
15
|
-
autorequire: mixology
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: false
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.2.0
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- anonymous z, Pat Farley, Dan Manges
|
8
|
+
autorequire: mixology
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-24 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Mixology enables objects to mixin and unmix modules.
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ext/mixology/extconf.rb
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
31
24
|
files:
|
32
25
|
- ext/mixology/mixology.c
|
33
26
|
- ext/mixology/extconf.rb
|
34
|
-
-
|
35
|
-
- test/mixology_test.rb
|
27
|
+
- lib/mixology_rubinius.rb
|
36
28
|
- test/test_helper.rb
|
29
|
+
- test/mixology_test.rb
|
37
30
|
- Rakefile
|
38
|
-
|
39
|
-
|
31
|
+
has_rdoc: false
|
32
|
+
homepage: http://mixology.rubyforge.org
|
33
|
+
post_install_message:
|
40
34
|
rdoc_options: []
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
-
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
48
50
|
requirements: []
|
49
51
|
|
50
|
-
|
52
|
+
rubyforge_project: mixology
|
53
|
+
rubygems_version: 1.3.1
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: Mixology enables objects to mixin and unmix modules.
|
57
|
+
test_files: []
|
51
58
|
|
data/ext/mixology/rbconfig.rb
DELETED
@@ -1,169 +0,0 @@
|
|
1
|
-
# This file was created by mkconfig.rb when ruby was built. Any
|
2
|
-
# changes made to this file will be lost the next time ruby is built.
|
3
|
-
|
4
|
-
module Config
|
5
|
-
RUBY_VERSION == "1.8.5" or
|
6
|
-
raise "ruby lib version (1.8.4) doesn't match executable version (#{RUBY_VERSION})"
|
7
|
-
|
8
|
-
TOPDIR = File.dirname(__FILE__).chomp!("/lib/ruby/1.8/i386-mingw32")
|
9
|
-
DESTDIR = '' unless defined? DESTDIR
|
10
|
-
CONFIG = {}
|
11
|
-
CONFIG["DESTDIR"] = DESTDIR
|
12
|
-
CONFIG["INSTALL"] = "/usr/bin/install -c"
|
13
|
-
CONFIG["prefix"] = (TOPDIR || DESTDIR + "/where/to/install/ruby-mingw32")
|
14
|
-
CONFIG["EXEEXT"] = ".exe"
|
15
|
-
CONFIG["ruby_install_name"] = "ruby"
|
16
|
-
CONFIG["RUBY_INSTALL_NAME"] = "ruby"
|
17
|
-
CONFIG["RUBY_SO_NAME"] = "msvcrt-ruby18"
|
18
|
-
CONFIG["SHELL"] = "/bin/sh"
|
19
|
-
CONFIG["PATH_SEPARATOR"] = ":"
|
20
|
-
CONFIG["PACKAGE_NAME"] = ""
|
21
|
-
CONFIG["PACKAGE_TARNAME"] = ""
|
22
|
-
CONFIG["PACKAGE_VERSION"] = ""
|
23
|
-
CONFIG["PACKAGE_STRING"] = ""
|
24
|
-
CONFIG["PACKAGE_BUGREPORT"] = ""
|
25
|
-
CONFIG["exec_prefix"] = "$(prefix)"
|
26
|
-
CONFIG["bindir"] = "$(exec_prefix)/bin"
|
27
|
-
CONFIG["sbindir"] = "$(exec_prefix)/sbin"
|
28
|
-
CONFIG["libexecdir"] = "$(exec_prefix)/libexec"
|
29
|
-
CONFIG["datadir"] = "$(prefix)/share"
|
30
|
-
CONFIG["sysconfdir"] = "$(prefix)/etc"
|
31
|
-
CONFIG["sharedstatedir"] = "$(prefix)/com"
|
32
|
-
CONFIG["localstatedir"] = "$(prefix)/var"
|
33
|
-
CONFIG["libdir"] = "$(exec_prefix)/lib"
|
34
|
-
CONFIG["includedir"] = "$(prefix)/include"
|
35
|
-
CONFIG["oldincludedir"] = "/usr/include"
|
36
|
-
CONFIG["infodir"] = "$(prefix)/info"
|
37
|
-
CONFIG["mandir"] = "$(prefix)/man"
|
38
|
-
CONFIG["build_alias"] = "i686-linux"
|
39
|
-
CONFIG["host_alias"] = "i586-mingw32msvc"
|
40
|
-
CONFIG["target_alias"] = "i386-mingw32"
|
41
|
-
CONFIG["ECHO_C"] = ""
|
42
|
-
CONFIG["ECHO_N"] = "-n"
|
43
|
-
CONFIG["ECHO_T"] = ""
|
44
|
-
CONFIG["LIBS"] = "-lwsock32 "
|
45
|
-
CONFIG["MAJOR"] = "1"
|
46
|
-
CONFIG["MINOR"] = "8"
|
47
|
-
CONFIG["TEENY"] = "4"
|
48
|
-
CONFIG["build"] = "i686-pc-linux"
|
49
|
-
CONFIG["build_cpu"] = "i686"
|
50
|
-
CONFIG["build_vendor"] = "pc"
|
51
|
-
CONFIG["build_os"] = "linux"
|
52
|
-
CONFIG["host"] = "i586-pc-mingw32msvc"
|
53
|
-
CONFIG["host_cpu"] = "i586"
|
54
|
-
CONFIG["host_vendor"] = "pc"
|
55
|
-
CONFIG["host_os"] = "mingw32msvc"
|
56
|
-
CONFIG["target"] = "i386-pc-mingw32"
|
57
|
-
CONFIG["target_cpu"] = "i386"
|
58
|
-
CONFIG["target_vendor"] = "pc"
|
59
|
-
CONFIG["target_os"] = "mingw32"
|
60
|
-
CONFIG["CC"] = "i586-mingw32msvc-gcc"
|
61
|
-
CONFIG["CFLAGS"] = "-g -O2 "
|
62
|
-
CONFIG["LDFLAGS"] = ""
|
63
|
-
CONFIG["CPPFLAGS"] = ""
|
64
|
-
CONFIG["OBJEXT"] = "o"
|
65
|
-
CONFIG["CPP"] = "i586-mingw32msvc-gcc -E"
|
66
|
-
CONFIG["EGREP"] = "grep -E"
|
67
|
-
CONFIG["GNU_LD"] = "yes"
|
68
|
-
CONFIG["CPPOUTFILE"] = "-o conftest.i"
|
69
|
-
CONFIG["OUTFLAG"] = "-o "
|
70
|
-
CONFIG["YACC"] = "bison -y"
|
71
|
-
CONFIG["RANLIB"] = "i586-mingw32msvc-ranlib"
|
72
|
-
CONFIG["AR"] = "i586-mingw32msvc-ar"
|
73
|
-
CONFIG["NM"] = "i586-mingw32msvc-nm"
|
74
|
-
CONFIG["WINDRES"] = "i586-mingw32msvc-windres"
|
75
|
-
CONFIG["DLLWRAP"] = "i586-mingw32msvc-dllwrap"
|
76
|
-
CONFIG["OBJDUMP"] = "i586-mingw32msvc-objdump"
|
77
|
-
CONFIG["LN_S"] = "ln -s"
|
78
|
-
CONFIG["SET_MAKE"] = ""
|
79
|
-
CONFIG["INSTALL_PROGRAM"] = "$(INSTALL)"
|
80
|
-
CONFIG["INSTALL_SCRIPT"] = "$(INSTALL)"
|
81
|
-
CONFIG["INSTALL_DATA"] = "$(INSTALL) -m 644"
|
82
|
-
CONFIG["RM"] = "rm -f"
|
83
|
-
CONFIG["CP"] = "cp"
|
84
|
-
CONFIG["MAKEDIRS"] = "mkdir -p"
|
85
|
-
CONFIG["LIBOBJS"] = " fileblocks$(U).o crypt$(U).o flock$(U).o acosh$(U).o win32$(U).o"
|
86
|
-
CONFIG["ALLOCA"] = ""
|
87
|
-
CONFIG["DLDFLAGS"] = " -Wl,--enable-auto-import,--export-all"
|
88
|
-
CONFIG["ARCH_FLAG"] = ""
|
89
|
-
CONFIG["STATIC"] = ""
|
90
|
-
CONFIG["CCDLFLAGS"] = ""
|
91
|
-
CONFIG["LDSHARED"] = "i586-mingw32msvc-gcc -shared -s"
|
92
|
-
CONFIG["DLEXT"] = "so"
|
93
|
-
CONFIG["DLEXT2"] = "dll"
|
94
|
-
CONFIG["LIBEXT"] = "a"
|
95
|
-
CONFIG["LINK_SO"] = ""
|
96
|
-
CONFIG["LIBPATHFLAG"] = " -L\"%s\""
|
97
|
-
CONFIG["RPATHFLAG"] = ""
|
98
|
-
CONFIG["LIBPATHENV"] = ""
|
99
|
-
CONFIG["TRY_LINK"] = ""
|
100
|
-
CONFIG["STRIP"] = "strip"
|
101
|
-
CONFIG["EXTSTATIC"] = ""
|
102
|
-
CONFIG["setup"] = "Setup"
|
103
|
-
CONFIG["MINIRUBY"] = "ruby -I/home/batsman/mess/current/ruby -rfake"
|
104
|
-
CONFIG["PREP"] = "fake.rb"
|
105
|
-
CONFIG["RUNRUBY"] = "$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`"
|
106
|
-
CONFIG["EXTOUT"] = ".ext"
|
107
|
-
CONFIG["ARCHFILE"] = ""
|
108
|
-
CONFIG["RDOCTARGET"] = ""
|
109
|
-
CONFIG["XCFLAGS"] = " -DRUBY_EXPORT"
|
110
|
-
CONFIG["XLDFLAGS"] = " -Wl,--stack,0x02000000 -L."
|
111
|
-
CONFIG["LIBRUBY_LDSHARED"] = "i586-mingw32msvc-gcc -shared -s"
|
112
|
-
CONFIG["LIBRUBY_DLDFLAGS"] = " -Wl,--enable-auto-import,--export-all -Wl,--out-implib=$(LIBRUBY)"
|
113
|
-
CONFIG["rubyw_install_name"] = "rubyw"
|
114
|
-
CONFIG["RUBYW_INSTALL_NAME"] = "rubyw"
|
115
|
-
CONFIG["LIBRUBY_A"] = "lib$(RUBY_SO_NAME)-static.a"
|
116
|
-
CONFIG["LIBRUBY_SO"] = "$(RUBY_SO_NAME).dll"
|
117
|
-
CONFIG["LIBRUBY_ALIASES"] = ""
|
118
|
-
CONFIG["LIBRUBY"] = "lib$(LIBRUBY_SO).a"
|
119
|
-
CONFIG["LIBRUBYARG"] = "$(LIBRUBYARG_SHARED)"
|
120
|
-
CONFIG["LIBRUBYARG_STATIC"] = "-l$(RUBY_SO_NAME)-static"
|
121
|
-
CONFIG["LIBRUBYARG_SHARED"] = "-l$(RUBY_SO_NAME)"
|
122
|
-
CONFIG["SOLIBS"] = "$(LIBS)"
|
123
|
-
CONFIG["DLDLIBS"] = ""
|
124
|
-
CONFIG["ENABLE_SHARED"] = "yes"
|
125
|
-
CONFIG["MAINLIBS"] = ""
|
126
|
-
CONFIG["COMMON_LIBS"] = "m"
|
127
|
-
CONFIG["COMMON_MACROS"] = ""
|
128
|
-
CONFIG["COMMON_HEADERS"] = "windows.h winsock.h"
|
129
|
-
CONFIG["EXPORT_PREFIX"] = ""
|
130
|
-
CONFIG["MINIOBJS"] = "dmydln.o"
|
131
|
-
CONFIG["MAKEFILES"] = "Makefile GNUmakefile"
|
132
|
-
CONFIG["arch"] = "i386-mingw32"
|
133
|
-
CONFIG["sitearch"] = "i386-msvcrt"
|
134
|
-
CONFIG["sitedir"] = "$(prefix)/lib/ruby/site_ruby"
|
135
|
-
CONFIG["configure_args"] = "'--host=i586-mingw32msvc' '--target=i386-mingw32' '--build=i686-linux' '--prefix=/home/batsman/mess/current/ruby-mingw32' 'build_alias=i686-linux' 'host_alias=i586-mingw32msvc' 'target_alias=i386-mingw32'"
|
136
|
-
CONFIG["NROFF"] = "/usr/bin/nroff"
|
137
|
-
CONFIG["MANTYPE"] = "doc"
|
138
|
-
CONFIG["LTLIBOBJS"] = " fileblocks$(U).lo crypt$(U).lo flock$(U).lo acosh$(U).lo win32$(U).lo"
|
139
|
-
CONFIG["ruby_version"] = "$(MAJOR).$(MINOR)"
|
140
|
-
CONFIG["rubylibdir"] = "$(libdir)/ruby/$(ruby_version)"
|
141
|
-
CONFIG["archdir"] = "$(rubylibdir)/$(arch)"
|
142
|
-
CONFIG["sitelibdir"] = "$(sitedir)/$(ruby_version)"
|
143
|
-
CONFIG["sitearchdir"] = "$(sitelibdir)/$(sitearch)"
|
144
|
-
CONFIG["topdir"] = File.dirname(__FILE__)
|
145
|
-
MAKEFILE_CONFIG = {}
|
146
|
-
CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
|
147
|
-
def Config::expand(val, config = CONFIG)
|
148
|
-
val.gsub!(/\$\$|\$\(([^()]+)\)|\$\{([^{}]+)\}/) do |var|
|
149
|
-
if !(v = $1 || $2)
|
150
|
-
'$'
|
151
|
-
elsif key = config[v = v[/\A[^:]+(?=(?::(.*?)=(.*))?\z)/]]
|
152
|
-
pat, sub = $1, $2
|
153
|
-
config[v] = false
|
154
|
-
Config::expand(key, config)
|
155
|
-
config[v] = key
|
156
|
-
key = key.gsub(/#{Regexp.quote(pat)}(?=\s|\z)/n) {sub} if pat
|
157
|
-
key
|
158
|
-
else
|
159
|
-
var
|
160
|
-
end
|
161
|
-
end
|
162
|
-
val
|
163
|
-
end
|
164
|
-
CONFIG.each_value do |val|
|
165
|
-
Config::expand(val)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
RbConfig = Config # compatibility for ruby-1.9
|
169
|
-
CROSS_COMPILING = nil unless defined? CROSS_COMPILING
|