public
Description: RubiGen - generator framework for your framework
Homepage: http://rubigen.rubyforge.org
Clone URL: git://github.com/drnic/rubigen.git
component_generator: specific subclasses for rails + merb generators
drnic (author)
Fri Apr 25 03:38:14 -0700 2008
commit  53ac8e7a63c77a38e3a32c8fcbedb5f4e8e9a39f
tree    a7d2686be3ffe0e9915ce985a06ccbc2623509f1
parent  51d5ef9dc8b185debab274825ced2eae362234d0
...
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
0
@@ -1,3 +1,8 @@
0
+== 1.3.0 2008-04-25
0
+
0
+* component_generator: specific subclasses for rails + merb generators,
0
+ not the generic RubiGen::Base
0
+
0
 == 1.2.3 2008-02-22
0
 
0
 * Remove -wKU flags from install_rubigen_scripts + ruby_app apps
...
1
2
3
4
5
 
 
6
7
8
...
1
2
3
 
 
4
5
6
7
8
0
@@ -1,8 +1,8 @@
0
 module Rubigen #:nodoc:
0
   module VERSION #:nodoc:
0
     MAJOR = 1
0
- MINOR = 2
0
- TINY = 4
0
+ MINOR = 3
0
+ TINY = 0
0
 
0
     STRING = [MAJOR, MINOR, TINY].join('.')
0
   end
...
1
2
3
4
5
6
 
 
 
 
 
 
7
8
9
...
30
31
32
 
 
 
 
 
 
 
 
 
 
 
33
34
35
...
46
47
48
49
 
50
51
52
53
...
1
 
 
 
 
 
2
3
4
5
6
7
8
9
10
...
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
...
58
59
60
 
61
62
63
64
65
0
@@ -1,9 +1,10 @@
0
 class ComponentGeneratorGenerator < RubiGen::Base
0
-
0
- default_options
0
-
0
- attr_reader :name, :class_name, :generator_type, :generator_path
0
-
0
+
0
+ default_options
0
+
0
+ attr_reader :name, :class_name
0
+ attr_reader :generator_type, :generator_path
0
+
0
   def initialize(runtime_args, runtime_options = {})
0
     super
0
     usage if args.empty?
0
@@ -30,6 +31,17 @@ class ComponentGeneratorGenerator < RubiGen::Base
0
     end
0
   end
0
 
0
+ def superclass_name
0
+ case (generator_type.to_sym rescue nil)
0
+ when :rails
0
+ "Rails::Generator::NamedBase"
0
+ when :merb
0
+ "Merb::GeneratorBase"
0
+ else
0
+ "RubiGen::Base"
0
+ end
0
+ end
0
+
0
   protected
0
     def banner
0
       <<-EOS
0
@@ -46,7 +58,7 @@ EOS
0
       # "Generated app file will include your name.",
0
       # "Default: none") { |options[:author]| }
0
     end
0
-
0
+
0
     def extract_options
0
     end
0
 end
0
\ No newline at end of file
...
1
 
2
3
4
...
 
1
2
3
4
0
@@ -1,4 +1,4 @@
0
-class <%= class_name %> < RubiGen::Base
0
+class <%= class_name %> < <%= superclass_name %>
0
   
0
   default_options :author => nil
0
   
...
6
7
8
9
 
10
11
12
13
 
14
15
16
...
22
23
24
 
 
 
 
25
26
27
...
36
37
38
39
 
40
41
42
...
45
46
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
49
50
...
60
61
62
63
 
64
65
66
...
6
7
8
 
9
10
11
12
 
13
14
15
16
...
22
23
24
25
26
27
28
29
30
31
...
40
41
42
 
43
44
45
46
...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
...
119
120
121
 
122
123
124
125
0
@@ -6,11 +6,11 @@ class TestGenerateComponentGenerator < Test::Unit::TestCase
0
   def setup
0
     bare_setup
0
   end
0
-
0
+
0
   def teardown
0
     bare_teardown
0
   end
0
-
0
+
0
   def test_generator_without_options
0
     name = "genname"
0
     run_generator('component_generator', [name], sources)
0
@@ -22,6 +22,10 @@ class TestGenerateComponentGenerator < Test::Unit::TestCase
0
     assert_generated_class("generators/#{name}/#{name}_generator") do |body|
0
       # assert_has_method body, "initialize" # as_has_m cannot pickup initialize(...) only initialize
0
       assert_has_method body, "manifest"
0
+
0
+ gen_class, superclass = body.match(%r{class ([\w:_]+) < ([\w:_]+)})[1..2]
0
+ assert_equal("GennameGenerator", gen_class)
0
+ assert_equal("RubiGen::Base", superclass)
0
     end
0
     assert_generated_class("test/test_#{name}_generator") do |body|
0
       assert_has_method body, "setup"
0
@@ -36,7 +40,7 @@ class TestGenerateComponentGenerator < Test::Unit::TestCase
0
     name = "genname"
0
     gen_type = "fooapp"
0
     run_generator('component_generator', [name, gen_type], sources)
0
-
0
+
0
     assert_generated_file "#{gen_type}_generators/#{name}/#{name}_generator.rb"
0
     assert_generated_file "#{gen_type}_generators/#{name}/USAGE"
0
     assert_generated_file "test/test_#{name}_generator.rb"
0
@@ -45,6 +49,61 @@ class TestGenerateComponentGenerator < Test::Unit::TestCase
0
     assert_generated_class "#{gen_type}_generators/#{name}/#{name}_generator" do |body|
0
       # assert_has_method body, "initialize" # as_has_m cannot pickup initialize(...) only initialize
0
       assert_has_method body, "manifest"
0
+ gen_class, superclass = body.match(%r{class ([\w:_]+) < ([\w:_]+)})[1..2]
0
+ assert_equal("GennameGenerator", gen_class)
0
+ assert_equal("RubiGen::Base", superclass)
0
+ end
0
+ assert_generated_class "test/test_#{name}_generator" do |body|
0
+ assert_has_method body, "setup"
0
+ assert_has_method body, "teardown"
0
+ assert_has_method body, "test_generator_without_options"
0
+ assert_has_method body, "sources"
0
+ assert_has_method body, "generator_path"
0
+ end
0
+ end
0
+
0
+ def test_generator_with_rails_generator_type
0
+ name = "genname"
0
+ gen_type = "rails"
0
+ run_generator('component_generator', [name, gen_type], sources)
0
+
0
+ assert_generated_file "#{gen_type}_generators/#{name}/#{name}_generator.rb"
0
+ assert_generated_file "#{gen_type}_generators/#{name}/USAGE"
0
+ assert_generated_file "test/test_#{name}_generator.rb"
0
+ assert_generated_file "test/test_generator_helper.rb"
0
+ assert_directory_exists "#{gen_type}_generators/#{name}/templates"
0
+ assert_generated_class "#{gen_type}_generators/#{name}/#{name}_generator" do |body|
0
+ # assert_has_method body, "initialize" # as_has_m cannot pickup initialize(...) only initialize
0
+ assert_has_method body, "manifest"
0
+ gen_class, superclass = body.match(%r{class ([\w:_]+) < ([\w:_]+)})[1..2]
0
+ assert_equal("GennameGenerator", gen_class)
0
+ assert_equal("Rails::Generator::NamedBase", superclass)
0
+ end
0
+ assert_generated_class "test/test_#{name}_generator" do |body|
0
+ assert_has_method body, "setup"
0
+ assert_has_method body, "teardown"
0
+ assert_has_method body, "test_generator_without_options"
0
+ assert_has_method body, "sources"
0
+ assert_has_method body, "generator_path"
0
+ end
0
+ end
0
+
0
+ def test_generator_with_merb_generator_type
0
+ name = "genname"
0
+ gen_type = "merb"
0
+ run_generator('component_generator', [name, gen_type], sources)
0
+
0
+ assert_generated_file "#{gen_type}_generators/#{name}/#{name}_generator.rb"
0
+ assert_generated_file "#{gen_type}_generators/#{name}/USAGE"
0
+ assert_generated_file "test/test_#{name}_generator.rb"
0
+ assert_generated_file "test/test_generator_helper.rb"
0
+ assert_directory_exists "#{gen_type}_generators/#{name}/templates"
0
+ assert_generated_class "#{gen_type}_generators/#{name}/#{name}_generator" do |body|
0
+ # assert_has_method body, "initialize" # as_has_m cannot pickup initialize(...) only initialize
0
+ assert_has_method body, "manifest"
0
+ gen_class, superclass = body.match(%r{class ([\w:_]+) < ([\w:_]+)})[1..2]
0
+ assert_equal("GennameGenerator", gen_class)
0
+ assert_equal("Merb::GeneratorBase", superclass)
0
     end
0
     assert_generated_class "test/test_#{name}_generator" do |body|
0
       assert_has_method body, "setup"
0
@@ -60,7 +119,7 @@ class TestGenerateComponentGenerator < Test::Unit::TestCase
0
     [RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"../#{generator_path}"))
0
     ]
0
   end
0
-
0
+
0
   def generator_path
0
     "rubygems_generators"
0
   end

Comments

    No one has commented yet.