module_creation_helper 0.1.0 → 0.2.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.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  == master
2
2
 
3
+ == 0.2.0 / 2008-12-14
4
+
5
+ * Remove the PluginAWeek namespace
6
+
3
7
  == 0.1.0 / 2008-07-06
4
8
 
5
9
  * Add support for specifying the parent class/module in the name of the class/module being created
data/Rakefile CHANGED
@@ -5,11 +5,11 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'module_creation_helper'
8
- s.version = '0.1.0'
8
+ s.version = '0.2.0'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Adds a helper method for creating new modules and classes at runtime.'
11
11
 
12
- s.files = FileList['{lib,test}/**/*'].to_a + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc)
12
+ s.files = FileList['{lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc)
13
13
  s.require_path = 'lib'
14
14
  s.has_rdoc = true
15
15
  s.test_files = Dir['test/**/*_test.rb']
@@ -1,63 +1,72 @@
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
1
+ module ModuleCreationHelper
2
+ module Extensions #:nodoc:
3
+ # Adds helper methods for easily generating new modules/classes
4
+ module Module
5
+ # Creates a new module with the specified name. This is essentially the
6
+ # same as actually defining the module like so:
7
+ #
8
+ # module NewModule
9
+ # end
10
+ #
11
+ # or as a class:
12
+ #
13
+ # class NewClass < SuperKlass
14
+ # end
15
+ #
16
+ # Configuration options:
17
+ # * +superclass+ - The class to inherit from. This only applies when using Class#create. Default is Object.
18
+ # * +parent+ - The class/module that contains this module. Default is Object.
19
+ #
20
+ # == Examples
21
+ #
22
+ # Module.create('Foo') # => Foo
23
+ # Module.create('Bar', :parent => Foo) # => Foo::Bar
24
+ # Class.create('Waddle') # => Waddle
25
+ # Class.create('Widdle', :parent => Waddle) # => Waddle::Widdle
26
+ # Class.create('Woddle', :superclass => Waddle::Widdle, :parent => Waddle) # => Waddle::Woddle
27
+ # Waddle::Woddle.superclass # => Waddle::Widdle
28
+ #
29
+ # == Setting the parent
30
+ #
31
+ # Rather than setting the parent directly using the +parent+ configuration
32
+ # option, you can specify it in the actual name of the class like so:
33
+ #
34
+ # Module.create('Foo::Bar') # => Foo::Bar
35
+ #
36
+ # This has the same effect as the following:
37
+ #
38
+ # Module.create('Bar', :parent => Foo)
39
+ def create(name, options = {}, &block)
40
+ # Validate the provided options
41
+ invalid_options = options.keys - [:superclass, :parent]
42
+ raise ArgumentError, "Unknown key(s): #{invalid_options.join(", ")}" unless invalid_options.empty?
43
+
44
+ # Validate usage of :superclass option
45
+ raise ArgumentError, 'Modules cannot have superclasses' if options[:superclass] && self.to_s == 'Module'
46
+
47
+ options = {:superclass => Object, :parent => Object}.merge(options)
48
+ parent = options[:parent]
49
+ superclass = options[:superclass]
50
+
51
+ if superclass != Object
52
+ superclass = " < ::#{superclass}"
53
+ else
54
+ superclass = ''
55
55
  end
56
+
57
+ mod = parent.class_eval <<-end_eval
58
+ #{self.to_s.downcase} #{name}#{superclass}
59
+ self
60
+ end
61
+ end_eval
62
+
63
+ mod.class_eval(&block) if block_given?
64
+ mod
56
65
  end
57
66
  end
58
67
  end
59
68
  end
60
69
 
61
70
  Module.class_eval do
62
- extend PluginAWeek::ModuleCreationHelper::Extensions::Module
71
+ extend ModuleCreationHelper::Extensions::Module
63
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: module_creation_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-06 00:00:00 -04:00
12
+ date: 2008-12-14 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  requirements: []
56
56
 
57
57
  rubyforge_project: pluginaweek
58
- rubygems_version: 1.1.1
58
+ rubygems_version: 1.2.0
59
59
  signing_key:
60
60
  specification_version: 2
61
61
  summary: Adds a helper method for creating new modules and classes at runtime.