mixology 0.1.0-jruby
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +71 -0
- data/ext/mixology/extconf.rb +3 -0
- data/ext/mixology/mixology.c +78 -0
- data/ext/mixology/rbconfig.rb +169 -0
- data/lib/mixology.jar +0 -0
- data/test/mixology_test.rb +170 -0
- data/test/test_helper.rb +20 -0
- metadata +45 -0
data/Rakefile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "rake"
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
if RUBY_PLATFORM =~ /java/
|
7
|
+
task :default => %w[clean compile_java test]
|
8
|
+
else
|
9
|
+
task :default => %w[clean compile test]
|
10
|
+
end
|
11
|
+
|
12
|
+
Rake::TestTask.new("test") do |t|
|
13
|
+
t.pattern = "test/**/*_test.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Builds the extension"
|
17
|
+
task :compile => ["ext/mixology/Makefile", "ext/mixology/mixology.#{Config::CONFIG['DLEXT']}" ]
|
18
|
+
|
19
|
+
file "ext/mixology/Makefile" => ["ext/mixology/extconf.rb"] do
|
20
|
+
Dir.chdir("ext/mixology") do
|
21
|
+
ruby "extconf.rb"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
file "ext/mixology/mixology.#{Config::CONFIG['DLEXT']}" do
|
26
|
+
Dir.chdir("ext/mixology") do
|
27
|
+
sh "make"
|
28
|
+
end
|
29
|
+
cp "ext/mixology/mixology.#{Config::CONFIG['DLEXT']}", "lib"
|
30
|
+
end
|
31
|
+
|
32
|
+
CLEAN.include %w[ext/mixology/Makefile ext/mixology/mixology.bundle lib/mixology.bundle]
|
33
|
+
CLEAN.include %w[ext/mixology/MixableService.class ext/mixology/mixable.jar lib/mixology.jar]
|
34
|
+
|
35
|
+
Gem::manage_gems
|
36
|
+
|
37
|
+
specification = Gem::Specification.new do |s|
|
38
|
+
s.name = "mixology"
|
39
|
+
s.summary = "Mixology enables objects to mixin and unmix modules."
|
40
|
+
s.version = "0.1.0"
|
41
|
+
s.author = "anonymous z, Pat Farley, Dan Manges"
|
42
|
+
s.description = s.summary
|
43
|
+
s.homepage = "http://mixology.rubyforge.org"
|
44
|
+
s.rubyforge_project = "mixology"
|
45
|
+
s.has_rdoc = false
|
46
|
+
s.autorequire = "mixology"
|
47
|
+
s.files = FileList['ext/**/*.{c,rb}', '{lib,test}/**/*.rb', '^[A-Z]+$', 'Rakefile'].to_a
|
48
|
+
if RUBY_PLATFORM =~ /mswin/
|
49
|
+
s.platform = Gem::Platform::WIN32
|
50
|
+
s.files += ["lib/mixology.so"]
|
51
|
+
elsif RUBY_PLATFORM =~ /java/
|
52
|
+
s.platform = "jruby"
|
53
|
+
s.files += ["lib/mixology.jar"]
|
54
|
+
else
|
55
|
+
s.platform = Gem::Platform::RUBY
|
56
|
+
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
57
|
+
end
|
58
|
+
end
|
59
|
+
Rake::GemPackageTask.new(specification) do |package|
|
60
|
+
package.need_zip = false
|
61
|
+
package.need_tar = false
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Compiles the JRuby extension"
|
65
|
+
task :compile_java do
|
66
|
+
Dir.chdir("ext/mixology") do
|
67
|
+
sh %{javac -source 1.4 -target 1.4 -classpath $JRUBY_HOME/lib/jruby.jar MixologyService.java}
|
68
|
+
sh %{jar cf mixology.jar MixologyService.class}
|
69
|
+
cp "mixology.jar", "../../lib/mixology.jar"
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
|
3
|
+
static void remove_nested_module(VALUE klass, VALUE include_class) {
|
4
|
+
|
5
|
+
if(RBASIC(RCLASS(klass)->super)->klass != RBASIC(RCLASS(include_class)->super)->klass) {
|
6
|
+
return;
|
7
|
+
}
|
8
|
+
if(RCLASS(RCLASS(include_class)->super)->super && BUILTIN_TYPE(RCLASS(include_class)->super) == T_ICLASS) {
|
9
|
+
remove_nested_module(RCLASS(klass)->super, RCLASS(include_class)->super);
|
10
|
+
}
|
11
|
+
RCLASS(klass)->super = RCLASS(RCLASS(klass)->super)->super;
|
12
|
+
}
|
13
|
+
|
14
|
+
static VALUE rb_unmix(VALUE self, VALUE module) {
|
15
|
+
VALUE klass;
|
16
|
+
for (klass = RBASIC(self)->klass; klass != rb_class_real(klass); klass = RCLASS(klass)->super) {
|
17
|
+
VALUE super = RCLASS(klass)->super;
|
18
|
+
if (BUILTIN_TYPE(super) == T_ICLASS) {
|
19
|
+
if (RBASIC(super)->klass == module) {
|
20
|
+
if(RCLASS(module)->super && BUILTIN_TYPE(RCLASS(module)->super) == T_ICLASS)
|
21
|
+
remove_nested_module(super, module);
|
22
|
+
RCLASS(klass)->super = RCLASS(RCLASS(klass)->super)->super;
|
23
|
+
rb_clear_cache();
|
24
|
+
}
|
25
|
+
}
|
26
|
+
}
|
27
|
+
return self;
|
28
|
+
}
|
29
|
+
|
30
|
+
static void add_module(VALUE self, VALUE module) {
|
31
|
+
VALUE super = RCLASS(rb_singleton_class(self))->super;
|
32
|
+
NEWOBJ(klass, struct RClass);
|
33
|
+
OBJSETUP(klass, rb_cClass, T_ICLASS);
|
34
|
+
|
35
|
+
if (BUILTIN_TYPE(module) == T_ICLASS) {
|
36
|
+
module = RBASIC(module)->klass;
|
37
|
+
}
|
38
|
+
if (!RCLASS(module)->iv_tbl) {
|
39
|
+
RCLASS(module)->iv_tbl = (void*)st_init_numtable();
|
40
|
+
}
|
41
|
+
klass->iv_tbl = RCLASS(module)->iv_tbl;
|
42
|
+
klass->m_tbl = RCLASS(module)->m_tbl;
|
43
|
+
klass->super = super;
|
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;
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
static VALUE rb_mixin(VALUE self, VALUE module) {
|
58
|
+
rb_unmix(self, module);
|
59
|
+
|
60
|
+
VALUE nested_modules = rb_mod_included_modules(module);
|
61
|
+
int index;
|
62
|
+
for (index = RARRAY(nested_modules)->len; index > 0; index--) {
|
63
|
+
VALUE nested_module = RARRAY(nested_modules)->ptr[index-1];
|
64
|
+
add_module(self, nested_module);
|
65
|
+
}
|
66
|
+
|
67
|
+
add_module(self, module);
|
68
|
+
|
69
|
+
rb_clear_cache();
|
70
|
+
return self;
|
71
|
+
}
|
72
|
+
|
73
|
+
void Init_mixology() {
|
74
|
+
VALUE Mixology = rb_define_module("Mixology");
|
75
|
+
rb_define_method(Mixology, "mixin", rb_mixin, 1);
|
76
|
+
rb_define_method(Mixology, "unmix", rb_unmix, 1);
|
77
|
+
rb_include_module(rb_cObject, Mixology);
|
78
|
+
}
|
@@ -0,0 +1,169 @@
|
|
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
|
data/lib/mixology.jar
ADDED
Binary file
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
|
3
|
+
class MixologyTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
test "mixin" do
|
6
|
+
mixin = Module.new { def foo; "foo"; end }
|
7
|
+
object = Object.new
|
8
|
+
object.mixin mixin
|
9
|
+
assert_equal "foo", object.foo
|
10
|
+
end
|
11
|
+
|
12
|
+
test "unmix" do
|
13
|
+
mixin = Module.new { def foo; "mixin"; end }
|
14
|
+
object = Class.new { def foo; "object"; end }.new
|
15
|
+
object.mixin mixin
|
16
|
+
assert_equal "mixin", object.foo
|
17
|
+
object.unmix mixin
|
18
|
+
assert_equal "object", object.foo
|
19
|
+
end
|
20
|
+
|
21
|
+
test "mixin twice" do
|
22
|
+
first_mixin = Module.new { def foo; "first"; end }
|
23
|
+
second_mixin = Module.new { def foo; "second"; end }
|
24
|
+
object = Object.new
|
25
|
+
object.mixin first_mixin
|
26
|
+
object.mixin second_mixin
|
27
|
+
assert_equal "second", object.foo
|
28
|
+
end
|
29
|
+
|
30
|
+
test "mixin to class" do
|
31
|
+
mix = Module.new { def foo; "foo"; end }
|
32
|
+
klass = Class.new { mixin mix }
|
33
|
+
assert_equal "foo", klass.foo
|
34
|
+
end
|
35
|
+
|
36
|
+
test "can mixin again" do
|
37
|
+
first_mixin = Module.new { def foo; "first"; end }
|
38
|
+
second_mixin = Module.new { def foo; "second"; end }
|
39
|
+
object = Object.new
|
40
|
+
object.mixin first_mixin
|
41
|
+
object.mixin second_mixin
|
42
|
+
object.mixin first_mixin
|
43
|
+
assert_equal "first", object.foo
|
44
|
+
end
|
45
|
+
|
46
|
+
test "unmix effects limited to instance" do
|
47
|
+
mixin = Module.new { def foo; "mixin"; end }
|
48
|
+
object = Class.new {include mixin}.new
|
49
|
+
assert_equal "mixin", object.foo
|
50
|
+
object.unmix mixin
|
51
|
+
assert_equal "mixin", object.foo
|
52
|
+
end
|
53
|
+
|
54
|
+
test "can add mod to an instance even when already included by class" do
|
55
|
+
mixin = Module.new { def foo; "mixin"; end }
|
56
|
+
klass = Class.new {include mixin; def foo; "class"; end }
|
57
|
+
object = klass.new
|
58
|
+
assert_equal "class", object.foo
|
59
|
+
object.mixin mixin
|
60
|
+
assert_equal "mixin", object.foo
|
61
|
+
end
|
62
|
+
|
63
|
+
test "included modules after mixin" do
|
64
|
+
mixin = Module.new
|
65
|
+
object = Object.new
|
66
|
+
object.mixin mixin
|
67
|
+
assert_equal [mixin, Mixology, Kernel], (class << object; self; end).included_modules
|
68
|
+
end
|
69
|
+
|
70
|
+
test "included modules after unmix" do
|
71
|
+
mixin = Module.new
|
72
|
+
object = Object.new
|
73
|
+
object.mixin mixin
|
74
|
+
object.unmix mixin
|
75
|
+
assert_equal [Mixology, Kernel], (class << object; self; end).included_modules
|
76
|
+
end
|
77
|
+
|
78
|
+
test "included modules after remix" do
|
79
|
+
mixin_one = Module.new
|
80
|
+
mixin_two = Module.new
|
81
|
+
object = Object.new
|
82
|
+
object.mixin mixin_one
|
83
|
+
object.mixin mixin_two
|
84
|
+
assert_equal [mixin_two, mixin_one, Mixology, Kernel], (class << object; self; end).included_modules
|
85
|
+
object.mixin mixin_one
|
86
|
+
assert_equal [mixin_one, mixin_two, Mixology, Kernel], (class << object; self; end).included_modules
|
87
|
+
end
|
88
|
+
|
89
|
+
test "mixin returns object" do
|
90
|
+
object = Object.new
|
91
|
+
mixin = Module.new
|
92
|
+
assert_equal object, object.mixin(mixin)
|
93
|
+
end
|
94
|
+
|
95
|
+
test "unmix returns object" do
|
96
|
+
object = Object.new
|
97
|
+
mixin = Module.new
|
98
|
+
object.mixin mixin
|
99
|
+
assert_equal object, object.unmix(mixin)
|
100
|
+
end
|
101
|
+
|
102
|
+
test "nested modules are mixedin" do
|
103
|
+
nested_module = Module.new { def foo; "foo"; end }
|
104
|
+
mixin = Module.new { include nested_module }
|
105
|
+
object = Object.new
|
106
|
+
object.mixin mixin
|
107
|
+
assert_equal [mixin, nested_module, Mixology, Kernel], (class << object; self; end).included_modules
|
108
|
+
end
|
109
|
+
|
110
|
+
test "nested modules are mixedin deeply" do
|
111
|
+
nested_module_ultimate = Module.new
|
112
|
+
nested_module_penultimate = Module.new { include nested_module_ultimate }
|
113
|
+
nested_module = Module.new { include nested_module_penultimate }
|
114
|
+
mixin = Module.new { include nested_module }
|
115
|
+
object = Object.new
|
116
|
+
object.mixin mixin
|
117
|
+
assert_equal [mixin, nested_module, nested_module_penultimate, nested_module_ultimate, Mixology, Kernel], (class << object; self; end).included_modules
|
118
|
+
end
|
119
|
+
|
120
|
+
test "nested modules are mixedin even if alrady mixed in" do
|
121
|
+
nested_module = Module.new { def foo; "foo"; end }
|
122
|
+
mixin = Module.new { include nested_module }
|
123
|
+
object = Object.new
|
124
|
+
object.mixin nested_module
|
125
|
+
object.mixin mixin
|
126
|
+
assert_equal [mixin, nested_module, nested_module, Mixology, Kernel], (class << object; self; end).included_modules
|
127
|
+
end
|
128
|
+
|
129
|
+
test "module is not unmixed if it is outside nested chain" do
|
130
|
+
nested_module = Module.new
|
131
|
+
mixin = Module.new { include nested_module }
|
132
|
+
object = Object.new
|
133
|
+
object.mixin nested_module
|
134
|
+
object.mixin mixin
|
135
|
+
object.unmix mixin
|
136
|
+
assert_equal [nested_module, Mixology, Kernel], (class << object; self; end).included_modules
|
137
|
+
end
|
138
|
+
|
139
|
+
test "nested modules are unmixed" do
|
140
|
+
nested_module = Module.new
|
141
|
+
mixin = Module.new { include nested_module }
|
142
|
+
object = Object.new
|
143
|
+
object.mixin mixin
|
144
|
+
object.unmix mixin
|
145
|
+
assert_equal [Mixology, Kernel], (class << object; self; end).included_modules
|
146
|
+
end
|
147
|
+
|
148
|
+
test "nested modules are unmixed deeply" do
|
149
|
+
nested_module_ultimate = Module.new
|
150
|
+
nested_module_penultimate = Module.new { include nested_module_ultimate }
|
151
|
+
nested_module = Module.new { include nested_module_penultimate }
|
152
|
+
mixin = Module.new { include nested_module }
|
153
|
+
object = Object.new
|
154
|
+
object.mixin mixin
|
155
|
+
object.unmix mixin
|
156
|
+
assert_equal [Mixology, Kernel], (class << object; self; end).included_modules
|
157
|
+
end
|
158
|
+
|
159
|
+
test "unrelated modules are not unmixed" do
|
160
|
+
unrelated = Module.new
|
161
|
+
nested_module = Module.new
|
162
|
+
mixin = Module.new { include nested_module }
|
163
|
+
object = Object.new
|
164
|
+
object.mixin unrelated
|
165
|
+
object.mixin mixin
|
166
|
+
object.unmix mixin
|
167
|
+
assert_equal [unrelated, Mixology, Kernel], (class << object; self; end).included_modules
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "rubygems"
|
3
|
+
|
4
|
+
if RUBY_PLATFORM =~ /java/
|
5
|
+
Test::Unit::TestCase.class_eval do
|
6
|
+
def self.test(test_name, &block)
|
7
|
+
define_method("test_#{test_name}", &block)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
else
|
11
|
+
begin
|
12
|
+
gem "dust"
|
13
|
+
require "dust"
|
14
|
+
rescue LoadError
|
15
|
+
raise "To run the tests, 'gem install dust'"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
|
20
|
+
require "mixology"
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
homepage: http://mixology.rubyforge.org
|
3
|
+
extensions: []
|
4
|
+
executables: []
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
post_install_message:
|
8
|
+
date: 2007-08-31 04:00:00 +00:00
|
9
|
+
files:
|
10
|
+
- ext/mixology/mixology.c
|
11
|
+
- ext/mixology/extconf.rb
|
12
|
+
- ext/mixology/rbconfig.rb
|
13
|
+
- test/mixology_test.rb
|
14
|
+
- test/test_helper.rb
|
15
|
+
- Rakefile
|
16
|
+
- lib/mixology.jar
|
17
|
+
rubygems_version: 0.9.4
|
18
|
+
rdoc_options: []
|
19
|
+
signing_key:
|
20
|
+
cert_chain:
|
21
|
+
name: mixology
|
22
|
+
has_rdoc: false
|
23
|
+
platform: jruby
|
24
|
+
summary: Mixology enables objects to mixin and unmix modules.
|
25
|
+
default_executable:
|
26
|
+
bindir: bin
|
27
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
28
|
+
version:
|
29
|
+
requirements:
|
30
|
+
- - '>'
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.0.0
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
specification_version: 1
|
36
|
+
test_files: []
|
37
|
+
dependencies: []
|
38
|
+
description: Mixology enables objects to mixin and unmix modules.
|
39
|
+
authors:
|
40
|
+
- anonymous z, Pat Farley, Dan Manges
|
41
|
+
email:
|
42
|
+
extra_rdoc_files: []
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project: mixology
|
45
|
+
autorequire: mixology
|