module_creation_helper 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +22 -0
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/{README → README.rdoc} +26 -28
- data/Rakefile +47 -38
- data/lib/module_creation_helper.rb +1 -60
- data/lib/module_creation_helper/extensions/module.rb +63 -0
- data/test/module_creation_helper_test.rb +52 -18
- data/test/test_helper.rb +1 -3
- metadata +11 -8
- data/CHANGELOG +0 -17
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
== master
|
2
|
+
|
3
|
+
== 0.1.0 / 2008-07-06
|
4
|
+
|
5
|
+
* Add support for specifying the parent class/module in the name of the class/module being created
|
6
|
+
* Don't depend on active_support
|
7
|
+
|
8
|
+
== 0.0.4 / 2008-05-05
|
9
|
+
|
10
|
+
* Updated documentation
|
11
|
+
|
12
|
+
== 0.0.3 / 2007-09-18
|
13
|
+
|
14
|
+
* Convert dos newlines to unix newlines
|
15
|
+
|
16
|
+
== 0.0.2 / 2007-02-02
|
17
|
+
|
18
|
+
* Released as a gem
|
19
|
+
|
20
|
+
== 0.0.1 / 2007-01-04
|
21
|
+
|
22
|
+
* Initial release
|
data/{MIT-LICENSE → LICENSE}
RENAMED
File without changes
|
data/{README → README.rdoc}
RENAMED
@@ -5,21 +5,21 @@ at runtime.
|
|
5
5
|
|
6
6
|
== Resources
|
7
7
|
|
8
|
-
Wiki
|
9
|
-
|
10
|
-
* http://wiki.pluginaweek.org/Module_creation_helper
|
11
|
-
|
12
8
|
API
|
13
9
|
|
14
10
|
* http://api.pluginaweek.org/module_creation_helper
|
15
11
|
|
12
|
+
Bugs
|
13
|
+
|
14
|
+
* http://pluginaweek.lighthouseapp.com/projects/13281-module_creation_helper
|
15
|
+
|
16
16
|
Development
|
17
17
|
|
18
|
-
* http://
|
18
|
+
* http://github.com/pluginaweek/module_creation_helper
|
19
19
|
|
20
20
|
Source
|
21
21
|
|
22
|
-
*
|
22
|
+
* git://github.com/pluginaweek/module_creation_helper.git
|
23
23
|
|
24
24
|
== Description
|
25
25
|
|
@@ -29,10 +29,8 @@ you will want to associate a runtime class with an actual name.
|
|
29
29
|
|
30
30
|
Traditionally, you would create new classes like so:
|
31
31
|
|
32
|
-
|
33
|
-
=>
|
34
|
-
>> Object.const_set('Foo', c)
|
35
|
-
=> Foo
|
32
|
+
c = Class.new # => #<Class:0x480e388>
|
33
|
+
Object.const_set('Foo', c) # => Foo
|
36
34
|
|
37
35
|
Although this isn't very hard, there are two problems:
|
38
36
|
(1) It's a repetitive process that should be DRYed.
|
@@ -50,9 +48,9 @@ To understand the second problem, consider the following:
|
|
50
48
|
When a class inherits from Foo, Ruby will invoke the +inherited+ callback. For
|
51
49
|
example,
|
52
50
|
|
53
|
-
|
54
|
-
inherited class: #<Class:0x47fb92c>, name:
|
55
|
-
=> #<Class:0x47fb92c>
|
51
|
+
c = Class.new(Foo)
|
52
|
+
# inherited class: #<Class:0x47fb92c>, name:
|
53
|
+
# => #<Class:0x47fb92c>
|
56
54
|
|
57
55
|
As you can see from output in this example, since the class has not yet been
|
58
56
|
assigned to a constant, it is anonymous and does not yet have a name.
|
@@ -67,9 +65,9 @@ Class since Class inherits from Module.
|
|
67
65
|
|
68
66
|
Using the same example as before,
|
69
67
|
|
70
|
-
|
71
|
-
inherited class: Bar, name: Bar
|
72
|
-
=> Bar
|
68
|
+
c = Class.create('Bar', :superclass => Foo)
|
69
|
+
# inherited class: Bar, name: Bar
|
70
|
+
# => Bar
|
73
71
|
|
74
72
|
As you can see, the name of the class is now available during the +inherited+
|
75
73
|
callback and is automatically assigned to the 'Bar' constant in Object.
|
@@ -79,24 +77,24 @@ callback and is automatically assigned to the 'Bar' constant in Object.
|
|
79
77
|
In addition to specifying the superclass, you can also specify the parent
|
80
78
|
module/class like so:
|
81
79
|
|
82
|
-
|
83
|
-
inherited class: MyModule::Bar, name: MyModule::Bar
|
84
|
-
=> MyModule::Bar
|
80
|
+
c = Class.create('Bar', :superclass => Foo, :parent => MyModule)
|
81
|
+
# inherited class: MyModule::Bar, name: MyModule::Bar
|
82
|
+
# => MyModule::Bar
|
85
83
|
|
86
84
|
=== Defining class/module methods
|
87
85
|
|
88
86
|
As you normally could when creating a new class, you can provide an additional
|
89
87
|
block that defines the body of the class. For example,
|
90
88
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
inherited class: MyModule::Bar, name: MyModule::Bar
|
97
|
-
=> Bar
|
98
|
-
|
99
|
-
=> "hello"
|
89
|
+
c = Class.create('Bar', :superclass => Foo, :parent => MyModule) do
|
90
|
+
def say_hello
|
91
|
+
'hello'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
# inherited class: MyModule::Bar, name: MyModule::Bar
|
95
|
+
# => Bar
|
96
|
+
Bar.new.say_hello
|
97
|
+
# => "hello"
|
100
98
|
|
101
99
|
== Dependencies
|
102
100
|
|
data/Rakefile
CHANGED
@@ -3,45 +3,54 @@ require 'rake/rdoctask'
|
|
3
3
|
require 'rake/gempackagetask'
|
4
4
|
require 'rake/contrib/sshpublisher'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
spec = Gem::Specification.new do |s|
|
7
|
+
s.name = 'module_creation_helper'
|
8
|
+
s.version = '0.1.0'
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.summary = 'Adds a helper method for creating new modules and classes at runtime.'
|
11
|
+
|
12
|
+
s.files = FileList['{lib,test}/**/*'].to_a + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc)
|
13
|
+
s.require_path = 'lib'
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.test_files = Dir['test/**/*_test.rb']
|
16
|
+
|
17
|
+
s.author = 'Aaron Pfeifer'
|
18
|
+
s.email = 'aaron@pluginaweek.org'
|
19
|
+
s.homepage = 'http://www.pluginaweek.org'
|
20
|
+
s.rubyforge_project = 'pluginaweek'
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Default: run all tests.'
|
12
24
|
task :default => :test
|
13
25
|
|
14
|
-
desc
|
26
|
+
desc "Test the #{spec.name} plugin."
|
15
27
|
Rake::TestTask.new(:test) do |t|
|
16
28
|
t.libs << 'lib'
|
17
|
-
t.
|
29
|
+
t.test_files = spec.test_files
|
18
30
|
t.verbose = true
|
19
31
|
end
|
20
32
|
|
21
|
-
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
namespace :test do
|
36
|
+
desc "Test the #{spec.name} plugin with Rcov."
|
37
|
+
Rcov::RcovTask.new(:rcov) do |t|
|
38
|
+
t.libs << 'lib'
|
39
|
+
t.test_files = spec.test_files
|
40
|
+
t.rcov_opts << '--exclude="^(?!lib/)"'
|
41
|
+
t.verbose = true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
rescue LoadError
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Generate documentation for the #{spec.name} plugin."
|
22
48
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
23
49
|
rdoc.rdoc_dir = 'rdoc'
|
24
|
-
rdoc.title =
|
50
|
+
rdoc.title = spec.name
|
51
|
+
rdoc.template = '../rdoc_template.rb'
|
25
52
|
rdoc.options << '--line-numbers' << '--inline-source'
|
26
|
-
rdoc.rdoc_files.include('README')
|
27
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
28
|
-
end
|
29
|
-
|
30
|
-
spec = Gem::Specification.new do |s|
|
31
|
-
s.name = PKG_NAME
|
32
|
-
s.version = PKG_VERSION
|
33
|
-
s.platform = Gem::Platform::RUBY
|
34
|
-
s.summary = 'Adds a helper method for creating new modules and classes at runtime.'
|
35
|
-
|
36
|
-
s.files = FileList['{lib,test}/**/*'].to_a + %w(CHANGELOG init.rb MIT-LICENSE Rakefile README)
|
37
|
-
s.require_path = 'lib'
|
38
|
-
s.autorequire = 'module_creation_helper'
|
39
|
-
s.has_rdoc = true
|
40
|
-
s.test_files = Dir['test/**/*_test.rb']
|
41
|
-
|
42
|
-
s.author = 'Aaron Pfeifer'
|
43
|
-
s.email = 'aaron@pluginaweek.org'
|
44
|
-
s.homepage = 'http://www.pluginaweek.org'
|
53
|
+
rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG.rdoc', 'LICENSE', 'lib/**/*.rb')
|
45
54
|
end
|
46
55
|
|
47
56
|
Rake::GemPackageTask.new(spec) do |p|
|
@@ -50,30 +59,30 @@ Rake::GemPackageTask.new(spec) do |p|
|
|
50
59
|
p.need_zip = true
|
51
60
|
end
|
52
61
|
|
53
|
-
desc 'Publish the beta gem'
|
62
|
+
desc 'Publish the beta gem.'
|
54
63
|
task :pgem => [:package] do
|
55
|
-
Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{
|
64
|
+
Rake::SshFilePublisher.new('aaron@pluginaweek.org', '/home/aaron/gems.pluginaweek.org/public/gems', 'pkg', "#{spec.name}-#{spec.version}.gem").upload
|
56
65
|
end
|
57
66
|
|
58
|
-
desc 'Publish the API documentation'
|
67
|
+
desc 'Publish the API documentation.'
|
59
68
|
task :pdoc => [:rdoc] do
|
60
|
-
Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{
|
69
|
+
Rake::SshDirPublisher.new('aaron@pluginaweek.org', "/home/aaron/api.pluginaweek.org/public/#{spec.name}", 'rdoc').upload
|
61
70
|
end
|
62
71
|
|
63
72
|
desc 'Publish the API docs and gem'
|
64
|
-
task :publish => [:pdoc, :release]
|
73
|
+
task :publish => [:pgem, :pdoc, :release]
|
65
74
|
|
66
75
|
desc 'Publish the release files to RubyForge.'
|
67
76
|
task :release => [:gem, :package] do
|
68
77
|
require 'rubyforge'
|
69
78
|
|
70
|
-
ruby_forge = RubyForge.new
|
79
|
+
ruby_forge = RubyForge.new.configure
|
71
80
|
ruby_forge.login
|
72
81
|
|
73
|
-
%w(
|
74
|
-
file = "pkg/#{
|
82
|
+
%w(gem tgz zip).each do |ext|
|
83
|
+
file = "pkg/#{spec.name}-#{spec.version}.#{ext}"
|
75
84
|
puts "Releasing #{File.basename(file)}..."
|
76
85
|
|
77
|
-
ruby_forge.add_release(
|
86
|
+
ruby_forge.add_release(spec.rubyforge_project, spec.name, spec.version, file)
|
78
87
|
end
|
79
88
|
end
|
@@ -1,60 +1 @@
|
|
1
|
-
module
|
2
|
-
module ModuleCreationHelper
|
3
|
-
# Creates a new module with the specified name. This is essentially the
|
4
|
-
# same as actually defining the module like so:
|
5
|
-
#
|
6
|
-
# module NewModule
|
7
|
-
# end
|
8
|
-
#
|
9
|
-
# or as a class:
|
10
|
-
#
|
11
|
-
# class NewClass < SuperKlass
|
12
|
-
# end
|
13
|
-
#
|
14
|
-
# Configuration options:
|
15
|
-
# <tt>superclass</tt> - The class to inherit from. This only applies when using Class#create. Default is Object.
|
16
|
-
# <tt>parent</tt> - The class/module that contains this module. Default is Object.
|
17
|
-
#
|
18
|
-
# Examples:
|
19
|
-
#
|
20
|
-
# Module.create('Foo') # => Foo
|
21
|
-
# Module.create('Bar', :parent => Foo) # => Foo::Bar
|
22
|
-
# Class.create('Waddle') # => Waddle
|
23
|
-
# Class.create('Widdle', :parent => Waddle) # => Waddle::Widdle
|
24
|
-
# Class.create('Woddle', :superclass => Waddle::Widdle, :parent => Waddle) # => Waddle::Woddle
|
25
|
-
# Waddle::Woddle.superclass # => Waddle::Widdle
|
26
|
-
def create(name, options = {}, &block)
|
27
|
-
options.assert_valid_keys(
|
28
|
-
:superclass,
|
29
|
-
:parent
|
30
|
-
)
|
31
|
-
raise ArgumentError, 'Modules cannot have superclasses' if options[:superclass] && self.to_s == 'Module'
|
32
|
-
|
33
|
-
options.reverse_merge!(
|
34
|
-
:superclass => Object,
|
35
|
-
:parent => Object
|
36
|
-
)
|
37
|
-
parent = options[:parent]
|
38
|
-
superclass = options[:superclass]
|
39
|
-
|
40
|
-
if superclass != Object
|
41
|
-
superclass = " < ::#{superclass}"
|
42
|
-
else
|
43
|
-
superclass = ''
|
44
|
-
end
|
45
|
-
|
46
|
-
parent.class_eval <<-end_eval
|
47
|
-
#{self.to_s.downcase} #{name}#{superclass}
|
48
|
-
end
|
49
|
-
end_eval
|
50
|
-
|
51
|
-
mod = parent.const_get(name)
|
52
|
-
mod.class_eval(&block) if block_given?
|
53
|
-
mod
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
Module.class_eval do
|
59
|
-
extend PluginAWeek::ModuleCreationHelper
|
60
|
-
end
|
1
|
+
require 'module_creation_helper/extensions/module'
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module PluginAWeek #:nodoc:
|
2
|
+
module ModuleCreationHelper
|
3
|
+
module Extensions #:nodoc:
|
4
|
+
# Adds helper methods for easily generating new modules/classes
|
5
|
+
module Module
|
6
|
+
# Creates a new module with the specified name. This is essentially the
|
7
|
+
# same as actually defining the module like so:
|
8
|
+
#
|
9
|
+
# module NewModule
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# or as a class:
|
13
|
+
#
|
14
|
+
# class NewClass < SuperKlass
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Configuration options:
|
18
|
+
# * +superclass+ - The class to inherit from. This only applies when using Class#create. Default is Object.
|
19
|
+
# * +parent+ - The class/module that contains this module. Default is Object.
|
20
|
+
#
|
21
|
+
# == Examples
|
22
|
+
#
|
23
|
+
# Module.create('Foo') # => Foo
|
24
|
+
# Module.create('Bar', :parent => Foo) # => Foo::Bar
|
25
|
+
# Class.create('Waddle') # => Waddle
|
26
|
+
# Class.create('Widdle', :parent => Waddle) # => Waddle::Widdle
|
27
|
+
# Class.create('Woddle', :superclass => Waddle::Widdle, :parent => Waddle) # => Waddle::Woddle
|
28
|
+
# Waddle::Woddle.superclass # => Waddle::Widdle
|
29
|
+
def create(name, options = {}, &block)
|
30
|
+
# Validate the provided options
|
31
|
+
invalid_options = options.keys - [:superclass, :parent]
|
32
|
+
raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
|
33
|
+
|
34
|
+
# Validate usage of :superclass option
|
35
|
+
raise ArgumentError, 'Modules cannot have superclasses' if options[:superclass] && self.to_s == 'Module'
|
36
|
+
|
37
|
+
options = {:superclass => Object, :parent => Object}.merge(options)
|
38
|
+
parent = options[:parent]
|
39
|
+
superclass = options[:superclass]
|
40
|
+
|
41
|
+
if superclass != Object
|
42
|
+
superclass = " < ::#{superclass}"
|
43
|
+
else
|
44
|
+
superclass = ''
|
45
|
+
end
|
46
|
+
|
47
|
+
mod = parent.class_eval <<-end_eval
|
48
|
+
#{self.to_s.downcase} #{name}#{superclass}
|
49
|
+
self
|
50
|
+
end
|
51
|
+
end_eval
|
52
|
+
|
53
|
+
mod.class_eval(&block) if block_given?
|
54
|
+
mod
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
Module.class_eval do
|
62
|
+
extend PluginAWeek::ModuleCreationHelper::Extensions::Module
|
63
|
+
end
|
@@ -4,9 +4,11 @@ module Ford
|
|
4
4
|
end
|
5
5
|
|
6
6
|
class Vehicle
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
class << self
|
8
|
+
attr_accessor :test_name
|
9
|
+
attr_accessor :test_inspect
|
10
|
+
attr_accessor :test_to_s
|
11
|
+
end
|
10
12
|
|
11
13
|
def self.inherited(base)
|
12
14
|
self.test_name = base.name
|
@@ -21,7 +23,7 @@ class ModuleCreationHelperTest < Test::Unit::TestCase
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
class
|
26
|
+
class ClassTest < Test::Unit::TestCase
|
25
27
|
def setup
|
26
28
|
@car = Class.create('Car')
|
27
29
|
end
|
@@ -31,7 +33,6 @@ class ModuleCreationHelperForClassTest < Test::Unit::TestCase
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def test_should_have_object_as_parent
|
34
|
-
assert_equal Object, @car.parent
|
35
36
|
assert Object.const_defined?('Car')
|
36
37
|
end
|
37
38
|
|
@@ -40,7 +41,7 @@ class ModuleCreationHelperForClassTest < Test::Unit::TestCase
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
|
-
class
|
44
|
+
class ClassWithSuperclassTest < Test::Unit::TestCase
|
44
45
|
def setup
|
45
46
|
@car = Class.create('Car', :superclass => Vehicle)
|
46
47
|
end
|
@@ -50,7 +51,6 @@ class ModuleCreationHelperForClassWithSuperclassTest < Test::Unit::TestCase
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def test_should_have_object_as_parent
|
53
|
-
assert_equal Object, @car.parent
|
54
54
|
assert Object.const_defined?('Car')
|
55
55
|
end
|
56
56
|
|
@@ -71,7 +71,7 @@ class ModuleCreationHelperForClassWithSuperclassTest < Test::Unit::TestCase
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
class
|
74
|
+
class ClassWithParentTest < Test::Unit::TestCase
|
75
75
|
def setup
|
76
76
|
@car = Class.create('Car', :parent => Ford)
|
77
77
|
end
|
@@ -81,7 +81,6 @@ class ModuleCreationHelperForClassWithParentTest < Test::Unit::TestCase
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_should_be_nested_within_parent
|
84
|
-
assert_equal Ford, @car.parent
|
85
84
|
assert Ford.const_defined?('Car')
|
86
85
|
end
|
87
86
|
|
@@ -90,7 +89,45 @@ class ModuleCreationHelperForClassWithParentTest < Test::Unit::TestCase
|
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
93
|
-
class
|
92
|
+
class ClassWithInferredParentTest < Test::Unit::TestCase
|
93
|
+
def setup
|
94
|
+
@car = Class.create('Ford::Car')
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_should_have_object_as_superclass
|
98
|
+
assert_equal Object, @car.superclass
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_should_be_nested_within_parent
|
102
|
+
assert Ford.const_defined?('Car')
|
103
|
+
end
|
104
|
+
|
105
|
+
def teardown
|
106
|
+
Ford.send(:remove_const, 'Car')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class ClassWithInferredParentAndConfiguredParenTest < Test::Unit::TestCase
|
111
|
+
def setup
|
112
|
+
Module.create('Car', :parent => Ford)
|
113
|
+
@part = Class.create('Car::Part', :parent => Ford)
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_should_have_object_as_superclass
|
117
|
+
assert_equal Object, @part.superclass
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_should_be_nested_within_parent
|
121
|
+
assert Ford::Car.const_defined?('Part')
|
122
|
+
end
|
123
|
+
|
124
|
+
def teardown
|
125
|
+
Ford::Car.send(:remove_const, 'Part')
|
126
|
+
Ford.send(:remove_const, 'Car')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class ClassWithSuperclassAndParentTest < Test::Unit::TestCase
|
94
131
|
def setup
|
95
132
|
Vehicle.test_name = nil
|
96
133
|
Vehicle.test_inspect = nil
|
@@ -104,7 +141,6 @@ class ModuleCreationHelperForClassWithSuperclassAndParentTest < Test::Unit::Test
|
|
104
141
|
end
|
105
142
|
|
106
143
|
def test_should_be_nested_within_parent
|
107
|
-
assert_equal Ford, @car.parent
|
108
144
|
assert Ford.const_defined?('Car')
|
109
145
|
end
|
110
146
|
|
@@ -125,7 +161,7 @@ class ModuleCreationHelperForClassWithSuperclassAndParentTest < Test::Unit::Test
|
|
125
161
|
end
|
126
162
|
end
|
127
163
|
|
128
|
-
class
|
164
|
+
class ClassWithDynamicSuperclassTest < Test::Unit::TestCase
|
129
165
|
def setup
|
130
166
|
@car = Class.create('Car')
|
131
167
|
@convertible = Class.create('Convertible', :superclass => @car)
|
@@ -141,7 +177,7 @@ class ModuleCreationHelperForClassWithDynamicSuperclassTest < Test::Unit::TestCa
|
|
141
177
|
end
|
142
178
|
end
|
143
179
|
|
144
|
-
class
|
180
|
+
class ClassWithCustomMethodsTest < Test::Unit::TestCase
|
145
181
|
def setup
|
146
182
|
@car = Class.create('Car', :superclass => Vehicle) do
|
147
183
|
def self.color
|
@@ -159,13 +195,12 @@ class ModuleCreationHelperForClassWithCustomMethods < Test::Unit::TestCase
|
|
159
195
|
end
|
160
196
|
end
|
161
197
|
|
162
|
-
class
|
198
|
+
class ModuleTest < Test::Unit::TestCase
|
163
199
|
def setup
|
164
200
|
@autopilot = Module.create('Autopilot')
|
165
201
|
end
|
166
202
|
|
167
203
|
def test_should_have_object_as_parent
|
168
|
-
assert_equal Object, @autopilot.parent
|
169
204
|
assert Object.const_defined?('Autopilot')
|
170
205
|
end
|
171
206
|
|
@@ -174,19 +209,18 @@ class ModuleCreationHelperForModuleTest < Test::Unit::TestCase
|
|
174
209
|
end
|
175
210
|
end
|
176
211
|
|
177
|
-
class
|
212
|
+
class ModuleWithSuperclassTest < Test::Unit::TestCase
|
178
213
|
def test_should_raise_an_exception
|
179
214
|
assert_raise(ArgumentError) {Module.create(nil, :superclass => Object)}
|
180
215
|
end
|
181
216
|
end
|
182
217
|
|
183
|
-
class
|
218
|
+
class ModuleWithParentTest < Test::Unit::TestCase
|
184
219
|
def setup
|
185
220
|
@autopilot = Module.create('Autopilot', :parent => Ford)
|
186
221
|
end
|
187
222
|
|
188
223
|
def test_should_be_nested_within_parent
|
189
|
-
assert_equal Ford, @autopilot.parent
|
190
224
|
assert Ford.const_defined?('Autopilot')
|
191
225
|
end
|
192
226
|
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: module_creation_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-07-06 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,14 +22,17 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
24
|
files:
|
25
|
+
- lib/module_creation_helper
|
26
|
+
- lib/module_creation_helper/extensions
|
27
|
+
- lib/module_creation_helper/extensions/module.rb
|
25
28
|
- lib/module_creation_helper.rb
|
26
29
|
- test/test_helper.rb
|
27
30
|
- test/module_creation_helper_test.rb
|
28
|
-
- CHANGELOG
|
31
|
+
- CHANGELOG.rdoc
|
29
32
|
- init.rb
|
30
|
-
-
|
33
|
+
- LICENSE
|
31
34
|
- Rakefile
|
32
|
-
- README
|
35
|
+
- README.rdoc
|
33
36
|
has_rdoc: true
|
34
37
|
homepage: http://www.pluginaweek.org
|
35
38
|
post_install_message:
|
@@ -51,8 +54,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
54
|
version:
|
52
55
|
requirements: []
|
53
56
|
|
54
|
-
rubyforge_project:
|
55
|
-
rubygems_version: 1.1.
|
57
|
+
rubyforge_project: pluginaweek
|
58
|
+
rubygems_version: 1.1.1
|
56
59
|
signing_key:
|
57
60
|
specification_version: 2
|
58
61
|
summary: Adds a helper method for creating new modules and classes at runtime.
|
data/CHANGELOG
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
*SVN*
|
2
|
-
|
3
|
-
*0.0.4* (May 5th, 2008)
|
4
|
-
|
5
|
-
* Updated documentation
|
6
|
-
|
7
|
-
*0.0.3* (September 18th, 2007)
|
8
|
-
|
9
|
-
* Convert dos newlines to unix newlines
|
10
|
-
|
11
|
-
*0.0.2* (February 2nd, 2007)
|
12
|
-
|
13
|
-
* Released as a gem
|
14
|
-
|
15
|
-
*0.0.1* (January 4th, 2007)
|
16
|
-
|
17
|
-
* Initial release
|