coderrr-mixico-inline 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,6 @@
1
+ Mixico
2
+ ======
3
+
4
+ This is a simple refactoring of why's mixico (http://github.com/why/mixico) to make it work with ruby 1.8.6. It has also been changed to use RubyInline to compile on the fly.
5
+
6
+ You can install the gem by clicking the rubygem icon above.
data/lib/mixico.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'rubygems'
2
+ require 'inline'
3
+
4
+ class Module
5
+ inline do |builder|
6
+ builder.c %q{
7
+ static VALUE disable_mixin(VALUE super)
8
+ {
9
+ VALUE p, kid;
10
+ VALUE module = self;
11
+
12
+ Check_Type(super, T_MODULE);
13
+ for (kid = module, p = RCLASS(module)->super; p; kid = p, p = RCLASS(p)->super) {
14
+ if (BUILTIN_TYPE(p) == T_ICLASS) {
15
+ if (RBASIC(p)->klass == super) {
16
+ RCLASS(kid)->super = RCLASS(p)->super;
17
+ rb_clear_cache();
18
+ return p;
19
+ }
20
+ }
21
+ }
22
+
23
+ return Qnil;
24
+ }
25
+ }
26
+
27
+ builder.c %q{
28
+ static VALUE enable_mixin(VALUE mixin)
29
+ {
30
+ VALUE p;
31
+ VALUE module = self;
32
+
33
+ Check_Type(mixin, T_ICLASS);
34
+ Check_Type(RBASIC(mixin)->klass, T_MODULE);
35
+ for (p = module; p; p = RCLASS(p)->super) {
36
+ if (RCLASS(p)->super == RCLASS(mixin)->super) {
37
+ RCLASS(p)->super = mixin;
38
+ return RBASIC(mixin)->klass;
39
+ }
40
+ }
41
+
42
+ return Qnil;
43
+ }
44
+ }
45
+ end
46
+ end
47
+
48
+ class Proc
49
+ def mixin mod
50
+ eval('self', binding).extend mod
51
+ end
52
+
53
+ def mixout mod
54
+ (class << eval('self', binding); self end).disable_mixin mod
55
+ end
56
+ end
57
+
58
+ class Module
59
+ def mix_eval mod, *args, &blk
60
+ blk.mixin mod
61
+ begin
62
+ yield *args
63
+ ensure
64
+ blk.mixout mod
65
+ end
66
+ end
67
+
68
+ alias_method :mix_exec, :mix_eval
69
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "mixico-inline"
3
+ s.version = "0.0.1"
4
+ s.summary = "1.8.6 compatible version of why's mixico"
5
+ s.email = "coderrr.contact@gmail.com"
6
+ s.homepage = "http://github.com/coderrr/mixico-inline"
7
+ s.description = "see http://github.com/why/mixico"
8
+ s.has_rdoc = false
9
+ s.authors = ["why", "banister", "coderrr"]
10
+ s.files = [
11
+ "README.markdown",
12
+ "mixico-inline.gemspec",
13
+ "lib/mixico.rb"
14
+ ]
15
+ s.test_files = ["test/mixico_test.rb"]
16
+ s.add_dependency("RubyInline", [">= 3.6.7"])
17
+ s.autorequire = 'mixico'
18
+ end
@@ -0,0 +1,35 @@
1
+ require 'test/unit'
2
+
3
+ require File.dirname(__FILE__) + "/../lib/mixico"
4
+
5
+ class MixicoTest < Test::Unit::TestCase
6
+ def setup
7
+ @p = Proc.new do
8
+ mixed_method
9
+ end
10
+
11
+ @m = Module.new do
12
+ def mixed_method
13
+ :im_mixed
14
+ end
15
+ end
16
+ end
17
+
18
+ def test_mixin
19
+ @p.mixin @m
20
+ assert_equal :im_mixed, @p.call
21
+ end
22
+
23
+ def test_mixout
24
+ @p.mixin @m
25
+ @p.mixout @m
26
+ assert_raises(NameError) { @p.call }
27
+ end
28
+
29
+ def test_mixout_after_call
30
+ @p.mixin @m
31
+ @p.call
32
+ @p.mixout @m
33
+ assert_raises(NameError) { @p.call }
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coderrr-mixico-inline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - why
8
+ - banister
9
+ - coderrr
10
+ autorequire: mixico
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2008-10-09 00:00:00 -07:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: RubyInline
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 3.6.7
25
+ version:
26
+ description: see http://github.com/why/mixico
27
+ email: coderrr.contact@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - README.markdown
36
+ - mixico-inline.gemspec
37
+ - lib/mixico.rb
38
+ has_rdoc: false
39
+ homepage: http://github.com/coderrr/mixico-inline
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: 1.8.6 compatible version of why's mixico
64
+ test_files:
65
+ - test/mixico_test.rb