prepend 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ 10/10/210 version 0.1.0
2
+ * release!
data/README.markdown ADDED
@@ -0,0 +1,31 @@
1
+ Prepend
2
+ --------------
3
+
4
+ (c) John Mair (banisterfiend), Asher (Asher)
5
+ MIT license
6
+
7
+ Enables modules to be prepended to classes (or other modules).
8
+
9
+ ** This is BETA software and has not yet been thoroughly tested, use
10
+ at own risk **
11
+
12
+ install the gem: **for testing purposes only**
13
+ `gem install prepend`
14
+
15
+ example:
16
+
17
+ module M
18
+ def hello
19
+ puts "hello!"
20
+ end
21
+ end
22
+
23
+ class A
24
+ def hello
25
+ puts "I feel only hate and loathing"
26
+ end
27
+ prepend M
28
+ end
29
+
30
+ # invoke class method
31
+ A.new.hello #=> hello!
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+
2
+ $LOAD_PATH.unshift File.join(File.expand_path(__FILE__), '..')
3
+
4
+ require 'rake/clean'
5
+ require 'rake/gempackagetask'
6
+
7
+ # get the texplay version
8
+ require 'lib/prepend/version'
9
+
10
+ $dlext = Config::CONFIG['DLEXT']
11
+
12
+ CLEAN.include("ext/**/*.#{$dlext}", "ext/**/*.log", "ext/**/*.o", "ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "ext/**/*.def", "ext/**/*.pdb")
13
+ CLOBBER.include("**/*.#{$dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
14
+
15
+ specification = Gem::Specification.new do |s|
16
+ s.name = "prepend"
17
+ s.summary = "Prepend modules in front of a class"
18
+ s.version = Prepend::VERSION
19
+ s.date = Time.now.strftime '%Y-%m-%d'
20
+ s.author = "John Mair (banisterfiend)"
21
+ s.email = 'jrmair@gmail.com'
22
+ s.description = s.summary
23
+ s.require_path = 'lib'
24
+ s.platform = Gem::Platform::RUBY
25
+ #s.platform = 'i386-mingw32'
26
+ s.homepage = "http://banisterfiend.wordpress.com"
27
+ s.has_rdoc = false
28
+
29
+ s.extensions = ["ext/prepend/extconf.rb"]
30
+ s.files = ["Rakefile", "README.markdown", "CHANGELOG",
31
+ "lib/prepend.rb", "lib/prepend/version.rb"] +
32
+ # ["lib/1.9/real_include.so", "lib/1.8/real_include.so"] +
33
+ FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
34
+ end
35
+
36
+ Rake::GemPackageTask.new(specification) do |package|
37
+ package.need_zip = false
38
+ package.need_tar = false
39
+ end
@@ -0,0 +1,23 @@
1
+ /* contains basic macros to facilitate ruby 1.8 and ruby 1.9 compatibility */
2
+
3
+ #ifndef GUARD_COMPAT_H
4
+ #define GUARD_COMPAT_H
5
+
6
+ #include <ruby.h>
7
+
8
+ /* macros for backwards compatibility with 1.8 */
9
+ #ifndef RUBY_19
10
+ # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
11
+ # define RCLASS_SUPER(c) (RCLASS(c)->super)
12
+ # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
13
+ # define OBJ_UNTRUSTED OBJ_TAINTED
14
+ # include "st.h"
15
+ #endif
16
+
17
+ # define FALSE 0
18
+ # define TRUE 1
19
+
20
+ /* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
21
+ #define KLASS_OF(c) (RBASIC(c)->klass)
22
+
23
+ #endif
@@ -0,0 +1,9 @@
1
+ require 'mkmf'
2
+
3
+ # 1.9 compatibility
4
+ $CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /1.9/
5
+
6
+ # let's use c99
7
+ $CFLAGS += " -std=c99"
8
+
9
+ create_makefile('prepend')
@@ -0,0 +1,57 @@
1
+ /* (c) 2010 John Mair (banisterfiend), MIT license */
2
+
3
+ #include "compat.h"
4
+ #include "ruby.h"
5
+
6
+ static VALUE
7
+ class_mod_wrapper_to_s(VALUE self)
8
+ {
9
+ return rb_iv_get(self, "__class_name__");
10
+ }
11
+
12
+ static VALUE
13
+ klass_to_s(VALUE self)
14
+ {
15
+ return rb_str_concat(rb_mod_name(self), rb_str_new2("*"));
16
+ }
17
+
18
+ static VALUE
19
+ rb_prepend_module(VALUE klass, VALUE module)
20
+ {
21
+ /* create wrapper module to hold current class's M_TBL */
22
+ VALUE class_mod_wrapper = rb_module_new();
23
+
24
+ /* clear the default M_TBL already allocated for the new wrapper module */
25
+ st_free_table(RCLASS_M_TBL(class_mod_wrapper));
26
+
27
+ /* set the wrapper module's M_TBL to the current class's */
28
+ RCLASS_M_TBL(class_mod_wrapper) = RCLASS_M_TBL(klass);
29
+
30
+ /* store name of current class in wrapper module for use by #to_s and #inspect */
31
+ rb_iv_set(class_mod_wrapper, "__class_name__", rb_mod_name(klass));
32
+
33
+ /* set current class's #to_s to return ClassName* */
34
+ rb_define_singleton_method(klass, "to_s", klass_to_s, 0);
35
+
36
+ /* set wrapper module's #to_s to name of current class */
37
+ rb_define_singleton_method(class_mod_wrapper, "to_s", class_mod_wrapper_to_s, 0);
38
+
39
+ /* erase the current class's M_TBL as we're now storing it in the wrapper module */
40
+ RCLASS_M_TBL(klass) = st_init_numtable();
41
+
42
+ /* include the wrapper module first */
43
+ rb_funcall(klass, rb_intern("include"), 1, class_mod_wrapper);
44
+
45
+ /* include the module we want to 'prepend' second, so that its M_TBL gets precedence over M_TBL of original class
46
+ (NB: original class's M_TBL is now stored in wrapper module) */
47
+ rb_funcall(klass, rb_intern("include"), 1, module);
48
+
49
+ rb_clear_cache();
50
+
51
+ return klass;
52
+ }
53
+
54
+ void
55
+ Init_prepend() {
56
+ rb_define_method(rb_cModule, "prepend", rb_prepend_module, 1);
57
+ }
data/lib/prepend.rb ADDED
@@ -0,0 +1,15 @@
1
+ direc = File.dirname(__FILE__)
2
+
3
+ begin
4
+ if RUBY_VERSION && RUBY_VERSION =~ /1.9/
5
+ require "#{direc}/1.9/prepend"
6
+ else
7
+ require "#{direc}/1.8/prepend"
8
+ end
9
+ rescue LoadError => e
10
+ require 'rbconfig'
11
+ dlext = Config::CONFIG['DLEXT']
12
+ require "#{direc}/prepend.#{dlext}"
13
+ end
14
+
15
+ require "#{direc}/prepend/version"
@@ -0,0 +1,3 @@
1
+ module Prepend
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prepend
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - John Mair (banisterfiend)
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-10 00:00:00 +13:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Prepend modules in front of a class
22
+ email: jrmair@gmail.com
23
+ executables: []
24
+
25
+ extensions:
26
+ - ext/prepend/extconf.rb
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - Rakefile
31
+ - README.markdown
32
+ - CHANGELOG
33
+ - lib/prepend.rb
34
+ - lib/prepend/version.rb
35
+ - ext/prepend/extconf.rb
36
+ - ext/prepend/compat.h
37
+ - ext/prepend/prepend.c
38
+ has_rdoc: false
39
+ homepage: http://banisterfiend.wordpress.com
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Prepend modules in front of a class
70
+ test_files: []
71
+