rubigen 1.0.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.
Files changed (120) hide show
  1. data/History.txt +3 -0
  2. data/License.txt +17 -0
  3. data/Manifest.txt +119 -0
  4. data/README.txt +204 -0
  5. data/Rakefile +142 -0
  6. data/bin/ruby_app +12 -0
  7. data/examples/rails_generators/applications/app/USAGE +16 -0
  8. data/examples/rails_generators/applications/app/app_generator.rb +177 -0
  9. data/examples/rails_generators/components/controller/USAGE +29 -0
  10. data/examples/rails_generators/components/controller/controller_generator.rb +37 -0
  11. data/examples/rails_generators/components/controller/templates/controller.rb +10 -0
  12. data/examples/rails_generators/components/controller/templates/functional_test.rb +18 -0
  13. data/examples/rails_generators/components/controller/templates/helper.rb +2 -0
  14. data/examples/rails_generators/components/controller/templates/view.html.erb +2 -0
  15. data/examples/rails_generators/components/integration_test/USAGE +8 -0
  16. data/examples/rails_generators/components/integration_test/integration_test_generator.rb +16 -0
  17. data/examples/rails_generators/components/integration_test/templates/integration_test.rb +10 -0
  18. data/examples/rails_generators/components/mailer/USAGE +16 -0
  19. data/examples/rails_generators/components/mailer/mailer_generator.rb +34 -0
  20. data/examples/rails_generators/components/mailer/templates/fixture.erb +3 -0
  21. data/examples/rails_generators/components/mailer/templates/fixture.rhtml +0 -0
  22. data/examples/rails_generators/components/mailer/templates/mailer.rb +13 -0
  23. data/examples/rails_generators/components/mailer/templates/unit_test.rb +37 -0
  24. data/examples/rails_generators/components/mailer/templates/view.erb +3 -0
  25. data/examples/rails_generators/components/mailer/templates/view.rhtml +0 -0
  26. data/examples/rails_generators/components/migration/USAGE +24 -0
  27. data/examples/rails_generators/components/migration/migration_generator.rb +20 -0
  28. data/examples/rails_generators/components/migration/templates/migration.rb +7 -0
  29. data/examples/rails_generators/components/model/USAGE +27 -0
  30. data/examples/rails_generators/components/model/model_generator.rb +38 -0
  31. data/examples/rails_generators/components/model/templates/fixtures.yml +15 -0
  32. data/examples/rails_generators/components/model/templates/migration.rb +14 -0
  33. data/examples/rails_generators/components/model/templates/model.rb +2 -0
  34. data/examples/rails_generators/components/model/templates/unit_test.rb +10 -0
  35. data/examples/rails_generators/components/observer/USAGE +13 -0
  36. data/examples/rails_generators/components/observer/observer_generator.rb +16 -0
  37. data/examples/rails_generators/components/observer/templates/observer.rb +2 -0
  38. data/examples/rails_generators/components/observer/templates/unit_test.rb +10 -0
  39. data/examples/rails_generators/components/plugin/USAGE +25 -0
  40. data/examples/rails_generators/components/plugin/plugin_generator.rb +39 -0
  41. data/examples/rails_generators/components/plugin/templates/MIT-LICENSE +20 -0
  42. data/examples/rails_generators/components/plugin/templates/README +13 -0
  43. data/examples/rails_generators/components/plugin/templates/Rakefile +22 -0
  44. data/examples/rails_generators/components/plugin/templates/USAGE +8 -0
  45. data/examples/rails_generators/components/plugin/templates/generator.rb +8 -0
  46. data/examples/rails_generators/components/plugin/templates/init.rb +1 -0
  47. data/examples/rails_generators/components/plugin/templates/install.rb +1 -0
  48. data/examples/rails_generators/components/plugin/templates/plugin.rb +1 -0
  49. data/examples/rails_generators/components/plugin/templates/tasks.rake +4 -0
  50. data/examples/rails_generators/components/plugin/templates/uninstall.rb +1 -0
  51. data/examples/rails_generators/components/plugin/templates/unit_test.rb +8 -0
  52. data/examples/rails_generators/components/resource/USAGE +23 -0
  53. data/examples/rails_generators/components/resource/resource_generator.rb +72 -0
  54. data/examples/rails_generators/components/resource/templates/USAGE +18 -0
  55. data/examples/rails_generators/components/resource/templates/controller.rb +2 -0
  56. data/examples/rails_generators/components/resource/templates/fixtures.yml +0 -0
  57. data/examples/rails_generators/components/resource/templates/functional_test.rb +20 -0
  58. data/examples/rails_generators/components/resource/templates/helper.rb +2 -0
  59. data/examples/rails_generators/components/scaffold/USAGE +25 -0
  60. data/examples/rails_generators/components/scaffold/scaffold_generator.rb +90 -0
  61. data/examples/rails_generators/components/scaffold/templates/controller.rb +85 -0
  62. data/examples/rails_generators/components/scaffold/templates/functional_test.rb +57 -0
  63. data/examples/rails_generators/components/scaffold/templates/helper.rb +2 -0
  64. data/examples/rails_generators/components/scaffold/templates/layout.html.erb +17 -0
  65. data/examples/rails_generators/components/scaffold/templates/style.css +74 -0
  66. data/examples/rails_generators/components/scaffold/templates/view_edit.html.erb +19 -0
  67. data/examples/rails_generators/components/scaffold/templates/view_index.html.erb +24 -0
  68. data/examples/rails_generators/components/scaffold/templates/view_new.html.erb +18 -0
  69. data/examples/rails_generators/components/scaffold/templates/view_show.html.erb +10 -0
  70. data/examples/rails_generators/components/session_migration/USAGE +10 -0
  71. data/examples/rails_generators/components/session_migration/session_migration_generator.rb +18 -0
  72. data/examples/rails_generators/components/session_migration/templates/migration.rb +16 -0
  73. data/examples/rails_generators/components/web_service/USAGE +24 -0
  74. data/examples/rails_generators/components/web_service/templates/api_definition.rb +5 -0
  75. data/examples/rails_generators/components/web_service/templates/controller.rb +8 -0
  76. data/examples/rails_generators/components/web_service/templates/functional_test.rb +19 -0
  77. data/examples/rails_generators/components/web_service/web_service_generator.rb +29 -0
  78. data/lib/rubigen/base.rb +168 -0
  79. data/lib/rubigen/commands.rb +632 -0
  80. data/lib/rubigen/generated_attribute.rb +40 -0
  81. data/lib/rubigen/generators/applications/ruby_app/USAGE +10 -0
  82. data/lib/rubigen/generators/applications/ruby_app/ruby_app_generator.rb +78 -0
  83. data/lib/rubigen/generators/applications/ruby_app/templates/README.txt +1 -0
  84. data/lib/rubigen/generators/applications/ruby_app/templates/configs/empty.log +0 -0
  85. data/lib/rubigen/generators/applications/ruby_app/templates/fresh_rakefile +10 -0
  86. data/lib/rubigen/generators/applications/ruby_app/templates/module.rb +5 -0
  87. data/lib/rubigen/generators/applications/ruby_app/templates/script/generate +13 -0
  88. data/lib/rubigen/generators/applications/ruby_app/templates/test_helper.rb +2 -0
  89. data/lib/rubigen/generators/components/test_unit/USAGE +14 -0
  90. data/lib/rubigen/generators/components/test_unit/templates/test +14 -0
  91. data/lib/rubigen/generators/components/test_unit/test_unit_generator.rb +26 -0
  92. data/lib/rubigen/helpers/generator_test_helper.rb +133 -0
  93. data/lib/rubigen/lookup.rb +296 -0
  94. data/lib/rubigen/manifest.rb +51 -0
  95. data/lib/rubigen/options.rb +136 -0
  96. data/lib/rubigen/scripts/destroy.rb +27 -0
  97. data/lib/rubigen/scripts/generate.rb +7 -0
  98. data/lib/rubigen/scripts/update.rb +12 -0
  99. data/lib/rubigen/scripts.rb +69 -0
  100. data/lib/rubigen/simple_logger.rb +44 -0
  101. data/lib/rubigen/spec.rb +42 -0
  102. data/lib/rubigen/version.rb +9 -0
  103. data/lib/rubigen.rb +44 -0
  104. data/script/destroy +9 -0
  105. data/script/generate +9 -0
  106. data/script/txt2html +65 -0
  107. data/setup.rb +1585 -0
  108. data/test/examples_from_rails/generator_test_helper.rb +195 -0
  109. data/test/examples_from_rails/test_rails_resource_generator.rb +106 -0
  110. data/test/examples_from_rails/test_rails_scaffold_generator.rb +185 -0
  111. data/test/test_generate_builtin_application.rb +24 -0
  112. data/test/test_generate_builtin_test_unit.rb +22 -0
  113. data/test/test_helper.rb +33 -0
  114. data/test/test_lookup.rb +103 -0
  115. data/website/index.html +352 -0
  116. data/website/index.txt +252 -0
  117. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  118. data/website/stylesheets/screen.css +138 -0
  119. data/website/template.rhtml +44 -0
  120. metadata +183 -0
@@ -0,0 +1,177 @@
1
+ require 'rbconfig'
2
+ require 'digest/md5'
3
+
4
+ class AppGenerator < RubiGen::Base
5
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
6
+ Config::CONFIG['ruby_install_name'])
7
+
8
+ DATABASES = %w(mysql oracle postgresql sqlite2 sqlite3 frontbase)
9
+
10
+ default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || "mysql"),
11
+ :shebang => DEFAULT_SHEBANG, :freeze => false
12
+ mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.."
13
+
14
+ def initialize(runtime_args, runtime_options = {})
15
+ super
16
+ usage if args.empty?
17
+ usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db]))
18
+ @destination_root = args.shift
19
+ @app_name = File.basename(File.expand_path(@destination_root))
20
+ end
21
+
22
+ def manifest
23
+ # Use /usr/bin/env if no special shebang was specified
24
+ script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
25
+ dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] }
26
+
27
+ # duplicate CGI::Session#generate_unique_id
28
+ md5 = Digest::MD5.new
29
+ now = Time.now
30
+ md5 << now.to_s
31
+ md5 << String(now.usec)
32
+ md5 << String(rand(0))
33
+ md5 << String($$)
34
+ md5 << @app_name
35
+
36
+ record do |m|
37
+ # Root directory and all subdirectories.
38
+ m.directory ''
39
+ BASEDIRS.each { |path| m.directory path }
40
+
41
+ # Root
42
+ m.file "fresh_rakefile", "Rakefile"
43
+ m.file "README", "README"
44
+
45
+ # Application
46
+ m.template "helpers/application.rb", "app/controllers/application.rb", :assigns => { :app_name => @app_name }
47
+ m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb"
48
+ m.template "helpers/test_helper.rb", "test/test_helper.rb"
49
+
50
+ # database.yml and .htaccess
51
+ m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => {
52
+ :app_name => @app_name,
53
+ :socket => options[:db] == "mysql" ? mysql_socket_location : nil
54
+ }
55
+ m.template "configs/routes.rb", "config/routes.rb"
56
+ m.template "configs/apache.conf", "public/.htaccess"
57
+
58
+ # Initializers
59
+ m.template "configs/initializers/inflections.rb", "config/initializers/inflections.rb"
60
+ m.template "configs/initializers/mime_types.rb", "config/initializers/mime_types.rb"
61
+
62
+ # Environments
63
+ m.file "environments/boot.rb", "config/boot.rb"
64
+ m.template "environments/environment.rb", "config/environment.rb", :assigns => { :freeze => options[:freeze], :app_name => @app_name, :app_secret => md5.hexdigest }
65
+ m.file "environments/production.rb", "config/environments/production.rb"
66
+ m.file "environments/development.rb", "config/environments/development.rb"
67
+ m.file "environments/test.rb", "config/environments/test.rb"
68
+
69
+ # Scripts
70
+ %w( about console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/inspector runner server plugin ).each do |file|
71
+ m.file "bin/#{file}", "script/#{file}", script_options
72
+ m.template "bin/win_script.cmd", "script/#{file}.cmd",
73
+ :assigns => { :filename => file } if RUBY_PLATFORM =~ /dos|win32|cygwin/i
74
+ end
75
+
76
+ # Dispatches
77
+ m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options
78
+ m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options
79
+ m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options
80
+
81
+ # HTML files
82
+ %w(404 500 index).each do |file|
83
+ m.template "html/#{file}.html", "public/#{file}.html"
84
+ end
85
+
86
+ m.template "html/favicon.ico", "public/favicon.ico"
87
+ m.template "html/robots.txt", "public/robots.txt"
88
+ m.file "html/images/rails.png", "public/images/rails.png"
89
+
90
+ # Javascripts
91
+ m.file "html/javascripts/prototype.js", "public/javascripts/prototype.js"
92
+ m.file "html/javascripts/effects.js", "public/javascripts/effects.js"
93
+ m.file "html/javascripts/dragdrop.js", "public/javascripts/dragdrop.js"
94
+ m.file "html/javascripts/controls.js", "public/javascripts/controls.js"
95
+ m.file "html/javascripts/application.js", "public/javascripts/application.js"
96
+
97
+ # Docs
98
+ m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
99
+
100
+ # Logs
101
+ %w(server production development test).each { |file|
102
+ m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
103
+ }
104
+ end
105
+ end
106
+
107
+ protected
108
+ def banner
109
+ "Usage: #{$0} /path/to/your/app [options]"
110
+ end
111
+
112
+ def add_options!(opt)
113
+ opt.separator ''
114
+ opt.separator 'Options:'
115
+ opt.on("-r", "--ruby=path", String,
116
+ "Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
117
+ "Default: #{DEFAULT_SHEBANG}") { |v| options[:shebang] = v }
118
+
119
+ opt.on("-d", "--database=name", String,
120
+ "Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite2/sqlite3).",
121
+ "Default: mysql") { |v| options[:db] = v }
122
+
123
+ opt.on("-f", "--freeze",
124
+ "Freeze Rails in vendor/rails from the gems generating the skeleton",
125
+ "Default: false") { |v| options[:freeze] = v }
126
+ end
127
+
128
+ def mysql_socket_location
129
+ MYSQL_SOCKET_LOCATIONS.find { |f| File.exists?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
130
+ end
131
+
132
+
133
+ # Installation skeleton. Intermediate directories are automatically
134
+ # created so don't sweat their absence here.
135
+ BASEDIRS = %w(
136
+ app/controllers
137
+ app/helpers
138
+ app/models
139
+ app/views/layouts
140
+ config/environments
141
+ config/initializers
142
+ db
143
+ doc
144
+ lib
145
+ lib/tasks
146
+ log
147
+ public/images
148
+ public/javascripts
149
+ public/stylesheets
150
+ script/performance
151
+ script/process
152
+ test/fixtures
153
+ test/functional
154
+ test/integration
155
+ test/mocks/development
156
+ test/mocks/test
157
+ test/unit
158
+ vendor
159
+ vendor/plugins
160
+ tmp/sessions
161
+ tmp/sockets
162
+ tmp/cache
163
+ tmp/pids
164
+ )
165
+
166
+ MYSQL_SOCKET_LOCATIONS = [
167
+ "/tmp/mysql.sock", # default
168
+ "/var/run/mysqld/mysqld.sock", # debian/gentoo
169
+ "/var/tmp/mysql.sock", # freebsd
170
+ "/var/lib/mysql/mysql.sock", # fedora
171
+ "/opt/local/lib/mysql/mysql.sock", # fedora
172
+ "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql
173
+ "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4
174
+ "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5
175
+ "/opt/lampp/var/mysql/mysql.sock" # xampp for linux
176
+ ]
177
+ end
@@ -0,0 +1,29 @@
1
+ Description:
2
+ Stubs out a new controller and its views. Pass the controller name, either
3
+ CamelCased or under_scored, and a list of views as arguments.
4
+
5
+ To create a controller within a module, specify the controller name as a
6
+ path like 'parent_module/controller_name'.
7
+
8
+ This generates a controller class in app/controllers, view templates in
9
+ app/views/controller_name, a helper class in app/helpers, and a functional
10
+ test suite in test/functional.
11
+
12
+ Example:
13
+ `./script/generate controller CreditCard open debit credit close`
14
+
15
+ Credit card controller with URLs like /credit_card/debit.
16
+ Controller: app/controllers/credit_card_controller.rb
17
+ Views: app/views/credit_card/debit.html.erb [...]
18
+ Helper: app/helpers/credit_card_helper.rb
19
+ Test: test/functional/credit_card_controller_test.rb
20
+
21
+ Modules Example:
22
+ `./script/generate controller 'admin/credit_card' suspend late_fee`
23
+
24
+ Credit card admin controller with URLs /admin/credit_card/suspend.
25
+ Controller: app/controllers/admin/credit_card_controller.rb
26
+ Views: app/views/admin/credit_card/debit.html.erb [...]
27
+ Helper: app/helpers/admin/credit_card_helper.rb
28
+ Test: test/functional/admin/credit_card_controller_test.rb
29
+
@@ -0,0 +1,37 @@
1
+ class ControllerGenerator < RubiGen::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
6
+
7
+ # Controller, helper, views, and test directories.
8
+ m.directory File.join('app/controllers', class_path)
9
+ m.directory File.join('app/helpers', class_path)
10
+ m.directory File.join('app/views', class_path, file_name)
11
+ m.directory File.join('test/functional', class_path)
12
+
13
+ # Controller class, functional test, and helper class.
14
+ m.template 'controller.rb',
15
+ File.join('app/controllers',
16
+ class_path,
17
+ "#{file_name}_controller.rb")
18
+
19
+ m.template 'functional_test.rb',
20
+ File.join('test/functional',
21
+ class_path,
22
+ "#{file_name}_controller_test.rb")
23
+
24
+ m.template 'helper.rb',
25
+ File.join('app/helpers',
26
+ class_path,
27
+ "#{file_name}_helper.rb")
28
+
29
+ # View template for each action.
30
+ actions.each do |action|
31
+ path = File.join('app/views', class_path, file_name, "#{action}.html.erb")
32
+ m.template 'view.html.erb', path,
33
+ :assigns => { :action => action, :path => path }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ class <%= class_name %>Controller < ApplicationController
2
+ <% if options[:scaffold] -%>
3
+ scaffold :<%= singular_name %>
4
+ <% end -%>
5
+ <% for action in actions -%>
6
+
7
+ def <%= action %>
8
+ end
9
+ <% end -%>
10
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
+ require '<%= file_path %>_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class <%= class_name %>Controller; def rescue_action(e) raise e end; end
6
+
7
+ class <%= class_name %>ControllerTest < Test::Unit::TestCase
8
+ def setup
9
+ @controller = <%= class_name %>Controller.new
10
+ @request = ActionController::TestRequest.new
11
+ @response = ActionController::TestResponse.new
12
+ end
13
+
14
+ # Replace this with your real tests.
15
+ def test_truth
16
+ assert true
17
+ end
18
+ end
@@ -0,0 +1,2 @@
1
+ module <%= class_name %>Helper
2
+ end
@@ -0,0 +1,2 @@
1
+ <h1><%= class_name %>#<%= action %></h1>
2
+ <p>Find me in <%= path %></p>
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Stubs out a new integration test. Pass the name of the test, either
3
+ CamelCased or under_scored, as an argument. The new test class is
4
+ generated in test/integration/testname_test.rb
5
+
6
+ Example:
7
+ `./script/generate integration_test GeneralStories` creates a GeneralStories
8
+ integration test in test/integration/general_stories_test.rb
@@ -0,0 +1,16 @@
1
+ class IntegrationTestGenerator < RubiGen::NamedBase
2
+ default_options :skip_migration => false
3
+
4
+ def manifest
5
+ record do |m|
6
+ # Check for class naming collisions.
7
+ m.class_collisions class_path, class_name, "#{class_name}Test"
8
+
9
+ # integration test directory
10
+ m.directory File.join('test/integration', class_path)
11
+
12
+ # integration test stub
13
+ m.template 'integration_test.rb', File.join('test/integration', class_path, "#{file_name}_test.rb")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ require "#{File.dirname(__FILE__)}<%= '/..' * class_nesting_depth %>/../test_helper"
2
+
3
+ class <%= class_name %>Test < ActionController::IntegrationTest
4
+ # fixtures :your, :models
5
+
6
+ # Replace this with your real tests.
7
+ def test_truth
8
+ assert true
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ Description:
2
+ Stubs out a new mailer and its views. Pass the mailer name, either
3
+ CamelCased or under_scored, and an optional list of emails as arguments.
4
+
5
+ This generates a mailer class in app/models, view templates in
6
+ app/views/mailer_name, a unit test in test/unit, and fixtures in
7
+ test/fixtures.
8
+
9
+ Example:
10
+ `./script/generate mailer Notifications signup forgot_password invoice`
11
+
12
+ creates a Notifications mailer class, views, test, and fixtures:
13
+ Mailer: app/models/notifications.rb
14
+ Views: app/views/notifications/signup.erb [...]
15
+ Test: test/unit/test/unit/notifications_test.rb
16
+ Fixtures: test/fixtures/notifications/signup [...]
@@ -0,0 +1,34 @@
1
+ class MailerGenerator < RubiGen::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions class_path, class_name, "#{class_name}Test"
6
+
7
+ # Mailer, view, test, and fixture directories.
8
+ m.directory File.join('app/models', class_path)
9
+ m.directory File.join('app/views', file_path)
10
+ m.directory File.join('test/unit', class_path)
11
+ m.directory File.join('test/fixtures', file_path)
12
+
13
+ # Mailer class and unit test.
14
+ m.template "mailer.rb", File.join('app/models',
15
+ class_path,
16
+ "#{file_name}.rb")
17
+ m.template "unit_test.rb", File.join('test/unit',
18
+ class_path,
19
+ "#{file_name}_test.rb")
20
+
21
+ # View template and fixture for each action.
22
+ actions.each do |action|
23
+ relative_path = File.join(file_path, action)
24
+ view_path = File.join('app/views', "#{relative_path}.erb")
25
+ fixture_path = File.join('test/fixtures', relative_path)
26
+
27
+ m.template "view.erb", view_path,
28
+ :assigns => { :action => action, :path => view_path }
29
+ m.template "fixture.erb", fixture_path,
30
+ :assigns => { :action => action, :path => view_path }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ <%= class_name %>#<%= action %>
2
+
3
+ Find me in <%= path %>
@@ -0,0 +1,13 @@
1
+ class <%= class_name %> < ActionMailer::Base
2
+ <% for action in actions -%>
3
+
4
+ def <%= action %>(sent_at = Time.now)
5
+ @subject = '<%= class_name %>#<%= action %>'
6
+ @body = {}
7
+ @recipients = ''
8
+ @from = ''
9
+ @sent_on = sent_at
10
+ @headers = {}
11
+ end
12
+ <% end -%>
13
+ end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
+
3
+ class <%= class_name %>Test < Test::Unit::TestCase
4
+ FIXTURES_PATH = File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../fixtures'
5
+ CHARSET = "utf-8"
6
+
7
+ include ActionMailer::Quoting
8
+
9
+ def setup
10
+ ActionMailer::Base.delivery_method = :test
11
+ ActionMailer::Base.perform_deliveries = true
12
+ ActionMailer::Base.deliveries = []
13
+
14
+ @expected = TMail::Mail.new
15
+ @expected.set_content_type "text", "plain", { "charset" => CHARSET }
16
+ @expected.mime_version = '1.0'
17
+ end
18
+
19
+ <% for action in actions -%>
20
+ def test_<%= action %>
21
+ @expected.subject = '<%= class_name %>#<%= action %>'
22
+ @expected.body = read_fixture('<%= action %>')
23
+ @expected.date = Time.now
24
+
25
+ assert_equal @expected.encoded, <%= class_name %>.create_<%= action %>(@expected.date).encoded
26
+ end
27
+
28
+ <% end -%>
29
+ private
30
+ def read_fixture(action)
31
+ IO.readlines("#{FIXTURES_PATH}/<%= file_path %>/#{action}")
32
+ end
33
+
34
+ def encode(subject)
35
+ quoted_printable(subject, CHARSET)
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ <%= class_name %>#<%= action %>
2
+
3
+ Find me in <%= path %>
@@ -0,0 +1,24 @@
1
+ Description:
2
+ Stubs out a new database migration. Pass the migration name, either
3
+ CamelCased or under_scored, as an argument. A migration class is generated
4
+ in db/migrate prefixed by the latest migration number.
5
+
6
+ You can name your migration in either of these formats to generate add/remove
7
+ column lines: AddColumnToTable or RemoveColumnFromTable
8
+
9
+ Example:
10
+ `./script/generate migration AddSslFlag`
11
+
12
+ With 4 existing migrations, this creates the AddSslFlag migration in
13
+ db/migrate/005_add_ssl_flag.rb
14
+
15
+ `./script/generate migration AddSslFlagToAccount`
16
+
17
+ This will create the AddSslFlagToAccount in db/migrate/005_add_ssl_flag_to_account.rb with
18
+ this in the Up migration:
19
+
20
+ add_column :accounts, :ssl_flag, :type, :null => :no?, :default => :maybe?
21
+
22
+ And this in the Down migration:
23
+
24
+ remove_column :accounts, :ssl_flag
@@ -0,0 +1,20 @@
1
+ class MigrationGenerator < RubiGen::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template 'migration.rb', 'db/migrate'
5
+ end
6
+ end
7
+
8
+ def auto_migration direction
9
+ case class_name.underscore
10
+ when /^(add|remove)_(.*)_(?:to|from)_(.*)/ then
11
+ action, col, tbl = $1, $2, $3.pluralize
12
+
13
+ unless (action == "add") ^ (direction == :up) then
14
+ %(\n add_column :#{tbl}, :#{col}, :type, :null => :no?, :default => :maybe?)
15
+ else
16
+ %(\n remove_column :#{tbl}, :#{col})
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ class <%= class_name.underscore.camelize %> < ActiveRecord::Migration
2
+ def self.up<%= auto_migration :up %>
3
+ end
4
+
5
+ def self.down<%= auto_migration :down %>
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ Description:
2
+ Stubs out a new model. Pass the model name, either CamelCased or
3
+ under_scored, and an optional list of attribute pairs as arguments.
4
+
5
+ Attribute pairs are column_name:sql_type arguments specifying the
6
+ model's attributes. Timestamps are added by default, so you don't have to
7
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
8
+
9
+ You don't have to think up every attribute up front, but it helps to
10
+ sketch out a few so you can start working with the model immediately.
11
+
12
+ This generates a model class in app/models, a unit test in test/unit,
13
+ a test fixture in test/fixtures/singular_name.yml, and a migration in
14
+ db/migrate.
15
+
16
+ Examples:
17
+ `./script/generate model account`
18
+
19
+ creates an Account model, test, fixture, and migration:
20
+ Model: app/models/account.rb
21
+ Test: test/unit/account_test.rb
22
+ Fixtures: test/fixtures/accounts.yml
23
+ Migration: db/migrate/XXX_add_accounts.rb
24
+
25
+ `./script/generate model post title:string body:text published:boolean`
26
+
27
+ creates a Post model with a string title, text body, and published flag.
@@ -0,0 +1,38 @@
1
+ class ModelGenerator < RubiGen::NamedBase
2
+ default_options :skip_migration => false
3
+
4
+ def manifest
5
+ record do |m|
6
+ # Check for class naming collisions.
7
+ m.class_collisions class_path, class_name, "#{class_name}Test"
8
+
9
+ # Model, test, and fixture directories.
10
+ m.directory File.join('app/models', class_path)
11
+ m.directory File.join('test/unit', class_path)
12
+ m.directory File.join('test/fixtures', class_path)
13
+
14
+ # Model class, unit test, and fixtures.
15
+ m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
16
+ m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
17
+ m.template 'fixtures.yml', File.join('test/fixtures', class_path, "#{table_name}.yml")
18
+
19
+ unless options[:skip_migration]
20
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => {
21
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
22
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
23
+ end
24
+ end
25
+ end
26
+
27
+ protected
28
+ def banner
29
+ "Usage: #{$0} generate ModelName [field:type, field:type]"
30
+ end
31
+
32
+ def add_options!(opt)
33
+ opt.separator ''
34
+ opt.separator 'Options:'
35
+ opt.on("--skip-migration",
36
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ one:
3
+ id: 1
4
+ <% for attribute in attributes -%>
5
+ <%= attribute.name %>: <%= attribute.default %>
6
+ <% end -%>
7
+ created_at: <%= Time.now.to_s(:db) %>
8
+ updated_at: <%= Time.now.to_s(:db) %>
9
+ two:
10
+ id: 2
11
+ <% for attribute in attributes -%>
12
+ <%= attribute.name %>: <%= attribute.default %>
13
+ <% end -%>
14
+ created_at: <%= Time.now.to_s(:db) %>
15
+ updated_at: <%= Time.now.to_s(:db) %>
@@ -0,0 +1,14 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %> do |t|
4
+ <% for attribute in attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <% end %>
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :<%= table_name %>
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ end
@@ -0,0 +1,10 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
+
3
+ class <%= class_name %>Test < Test::Unit::TestCase
4
+ fixtures :<%= table_name %>
5
+
6
+ # Replace this with your real tests.
7
+ def test_truth
8
+ assert true
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ Description:
2
+ Stubs out a new observer. Pass the observer name, either CamelCased or
3
+ under_scored, as an argument.
4
+
5
+ The generator creates an observer class in app/models and a unit test in
6
+ test/unit.
7
+
8
+ Example:
9
+ `./script/generate observer Account`
10
+
11
+ creates an Account observer and unit test:
12
+ Observer: app/models/account_observer.rb
13
+ Test: test/unit/account_observer_test.rb
@@ -0,0 +1,16 @@
1
+ class ObserverGenerator < RubiGen::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions class_path, "#{class_name}Observer", "#{class_name}ObserverTest"
6
+
7
+ # Observer, and test directories.
8
+ m.directory File.join('app/models', class_path)
9
+ m.directory File.join('test/unit', class_path)
10
+
11
+ # Observer class and unit test fixtures.
12
+ m.template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb")
13
+ m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %>Observer < ActiveRecord::Observer
2
+ end