railties 3.0.0.beta
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 +2201 -0
- data/README +286 -0
- data/bin/rails +11 -0
- data/builtin/rails_info/rails/info.rb +147 -0
- data/builtin/rails_info/rails/info_controller.rb +15 -0
- data/builtin/rails_info/rails/info_helper.rb +2 -0
- data/builtin/routes.rb +3 -0
- data/guides/files/javascripts/code_highlighter.js +188 -0
- data/guides/files/javascripts/guides.js +7 -0
- data/guides/files/javascripts/highlighters.js +90 -0
- data/guides/files/stylesheets/main.css +441 -0
- data/guides/files/stylesheets/print.css +52 -0
- data/guides/files/stylesheets/reset.css +43 -0
- data/guides/files/stylesheets/style.css +13 -0
- data/guides/files/stylesheets/syntax.css +31 -0
- data/guides/images/belongs_to.png +0 -0
- data/guides/images/book_icon.gif +0 -0
- data/guides/images/bullet.gif +0 -0
- data/guides/images/chapters_icon.gif +0 -0
- data/guides/images/check_bullet.gif +0 -0
- data/guides/images/credits_pic_blank.gif +0 -0
- data/guides/images/csrf.png +0 -0
- data/guides/images/customized_error_messages.png +0 -0
- data/guides/images/error_messages.png +0 -0
- data/guides/images/feature_tile.gif +0 -0
- data/guides/images/footer_tile.gif +0 -0
- data/guides/images/fxn.png +0 -0
- data/guides/images/grey_bullet.gif +0 -0
- data/guides/images/habtm.png +0 -0
- data/guides/images/has_many.png +0 -0
- data/guides/images/has_many_through.png +0 -0
- data/guides/images/has_one.png +0 -0
- data/guides/images/has_one_through.png +0 -0
- data/guides/images/header_backdrop.png +0 -0
- data/guides/images/header_tile.gif +0 -0
- data/guides/images/i18n/demo_localized_pirate.png +0 -0
- data/guides/images/i18n/demo_translated_en.png +0 -0
- data/guides/images/i18n/demo_translated_pirate.png +0 -0
- data/guides/images/i18n/demo_translation_missing.png +0 -0
- data/guides/images/i18n/demo_untranslated.png +0 -0
- data/guides/images/icons/README +5 -0
- data/guides/images/icons/callouts/1.png +0 -0
- data/guides/images/icons/callouts/10.png +0 -0
- data/guides/images/icons/callouts/11.png +0 -0
- data/guides/images/icons/callouts/12.png +0 -0
- data/guides/images/icons/callouts/13.png +0 -0
- data/guides/images/icons/callouts/14.png +0 -0
- data/guides/images/icons/callouts/15.png +0 -0
- data/guides/images/icons/callouts/2.png +0 -0
- data/guides/images/icons/callouts/3.png +0 -0
- data/guides/images/icons/callouts/4.png +0 -0
- data/guides/images/icons/callouts/5.png +0 -0
- data/guides/images/icons/callouts/6.png +0 -0
- data/guides/images/icons/callouts/7.png +0 -0
- data/guides/images/icons/callouts/8.png +0 -0
- data/guides/images/icons/callouts/9.png +0 -0
- data/guides/images/icons/caution.png +0 -0
- data/guides/images/icons/example.png +0 -0
- data/guides/images/icons/home.png +0 -0
- data/guides/images/icons/important.png +0 -0
- data/guides/images/icons/next.png +0 -0
- data/guides/images/icons/note.png +0 -0
- data/guides/images/icons/prev.png +0 -0
- data/guides/images/icons/tip.png +0 -0
- data/guides/images/icons/up.png +0 -0
- data/guides/images/icons/warning.png +0 -0
- data/guides/images/nav_arrow.gif +0 -0
- data/guides/images/polymorphic.png +0 -0
- data/guides/images/posts_index.png +0 -0
- data/guides/images/rails_guides_logo.gif +0 -0
- data/guides/images/rails_logo_remix.gif +0 -0
- data/guides/images/rails_welcome.png +0 -0
- data/guides/images/session_fixation.png +0 -0
- data/guides/images/tab_grey.gif +0 -0
- data/guides/images/tab_info.gif +0 -0
- data/guides/images/tab_note.gif +0 -0
- data/guides/images/tab_red.gif +0 -0
- data/guides/images/tab_yellow.gif +0 -0
- data/guides/images/tab_yellow.png +0 -0
- data/guides/images/validation_error_messages.png +0 -0
- data/guides/rails_guides.rb +44 -0
- data/guides/rails_guides/generator.rb +178 -0
- data/guides/rails_guides/helpers.rb +34 -0
- data/guides/rails_guides/indexer.rb +55 -0
- data/guides/rails_guides/levenshtein.rb +31 -0
- data/guides/rails_guides/textile_extensions.rb +41 -0
- data/guides/source/2_2_release_notes.textile +422 -0
- data/guides/source/2_3_release_notes.textile +610 -0
- data/guides/source/3_0_release_notes.textile +560 -0
- data/guides/source/action_controller_overview.textile +783 -0
- data/guides/source/action_mailer_basics.textile +437 -0
- data/guides/source/action_view_overview.textile +1481 -0
- data/guides/source/active_record_basics.textile +204 -0
- data/guides/source/active_record_querying.textile +961 -0
- data/guides/source/active_support_core_extensions.textile +1835 -0
- data/guides/source/activerecord_validations_callbacks.textile +1127 -0
- data/guides/source/ajax_on_rails.textile +342 -0
- data/guides/source/association_basics.textile +1816 -0
- data/guides/source/caching_with_rails.textile +390 -0
- data/guides/source/command_line.textile +589 -0
- data/guides/source/configuring.textile +290 -0
- data/guides/source/contribute.textile +71 -0
- data/guides/source/contributing_to_rails.textile +272 -0
- data/guides/source/credits.textile.erb +52 -0
- data/guides/source/debugging_rails_applications.textile +709 -0
- data/guides/source/form_helpers.textile +768 -0
- data/guides/source/generators.textile +378 -0
- data/guides/source/getting_started.textile +1310 -0
- data/guides/source/i18n.textile +879 -0
- data/guides/source/index.textile.erb +124 -0
- data/guides/source/layout.html.erb +103 -0
- data/guides/source/layouts_and_rendering.textile +979 -0
- data/guides/source/migrations.textile +591 -0
- data/guides/source/nested_model_forms.textile +222 -0
- data/guides/source/performance_testing.textile +531 -0
- data/guides/source/plugins.textile +1512 -0
- data/guides/source/rails_application_templates.textile +238 -0
- data/guides/source/rails_on_rack.textile +306 -0
- data/guides/source/routing.textile +903 -0
- data/guides/source/security.textile +984 -0
- data/guides/source/testing.textile +946 -0
- data/lib/generators/erb.rb +8 -0
- data/lib/generators/erb/controller/controller_generator.rb +21 -0
- data/lib/generators/erb/controller/templates/view.html.erb +2 -0
- data/lib/generators/erb/mailer/mailer_generator.rb +20 -0
- data/lib/generators/erb/mailer/templates/view.text.erb +3 -0
- data/lib/generators/erb/scaffold/scaffold_generator.rb +53 -0
- data/lib/generators/erb/scaffold/templates/_form.html.erb +13 -0
- data/lib/generators/erb/scaffold/templates/edit.html.erb +6 -0
- data/lib/generators/erb/scaffold/templates/index.html.erb +27 -0
- data/lib/generators/erb/scaffold/templates/layout.html.erb +16 -0
- data/lib/generators/erb/scaffold/templates/new.html.erb +5 -0
- data/lib/generators/erb/scaffold/templates/show.html.erb +10 -0
- data/lib/generators/rails/app/USAGE +9 -0
- data/lib/generators/rails/app/app_generator.rb +262 -0
- data/lib/generators/rails/app/templates/Gemfile +34 -0
- data/lib/generators/rails/app/templates/README +243 -0
- data/lib/generators/rails/app/templates/Rakefile +10 -0
- data/lib/generators/rails/app/templates/app/controllers/application_controller.rb +3 -0
- data/lib/generators/rails/app/templates/app/helpers/application_helper.rb +2 -0
- data/lib/generators/rails/app/templates/app/models/.empty_directory +0 -0
- data/lib/generators/rails/app/templates/app/views/layouts/.empty_directory +0 -0
- data/lib/generators/rails/app/templates/config.ru +4 -0
- data/lib/generators/rails/app/templates/config/application.rb +51 -0
- data/lib/generators/rails/app/templates/config/boot.rb +17 -0
- data/lib/generators/rails/app/templates/config/databases/frontbase.yml +28 -0
- data/lib/generators/rails/app/templates/config/databases/ibm_db.yml +71 -0
- data/lib/generators/rails/app/templates/config/databases/mysql.yml +60 -0
- data/lib/generators/rails/app/templates/config/databases/oracle.yml +39 -0
- data/lib/generators/rails/app/templates/config/databases/postgresql.yml +51 -0
- data/lib/generators/rails/app/templates/config/databases/sqlite3.yml +22 -0
- data/lib/generators/rails/app/templates/config/environment.rb +5 -0
- data/lib/generators/rails/app/templates/config/environments/development.rb.tt +19 -0
- data/lib/generators/rails/app/templates/config/environments/production.rb.tt +33 -0
- data/lib/generators/rails/app/templates/config/environments/test.rb.tt +29 -0
- data/lib/generators/rails/app/templates/config/initializers/backtrace_silencers.rb +7 -0
- data/lib/generators/rails/app/templates/config/initializers/cookie_verification_secret.rb.tt +7 -0
- data/lib/generators/rails/app/templates/config/initializers/inflections.rb +10 -0
- data/lib/generators/rails/app/templates/config/initializers/mime_types.rb +5 -0
- data/lib/generators/rails/app/templates/config/initializers/session_store.rb.tt +15 -0
- data/lib/generators/rails/app/templates/config/locales/en.yml +5 -0
- data/lib/generators/rails/app/templates/config/routes.rb +58 -0
- data/lib/generators/rails/app/templates/db/seeds.rb +7 -0
- data/lib/generators/rails/app/templates/doc/README_FOR_APP +2 -0
- data/lib/generators/rails/app/templates/gitignore +4 -0
- data/lib/generators/rails/app/templates/public/404.html +26 -0
- data/lib/generators/rails/app/templates/public/422.html +26 -0
- data/lib/generators/rails/app/templates/public/500.html +26 -0
- data/lib/generators/rails/app/templates/public/favicon.ico +0 -0
- data/lib/generators/rails/app/templates/public/images/rails.png +0 -0
- data/lib/generators/rails/app/templates/public/index.html +278 -0
- data/lib/generators/rails/app/templates/public/javascripts/application.js +2 -0
- data/lib/generators/rails/app/templates/public/javascripts/controls.js +963 -0
- data/lib/generators/rails/app/templates/public/javascripts/dragdrop.js +973 -0
- data/lib/generators/rails/app/templates/public/javascripts/effects.js +1128 -0
- data/lib/generators/rails/app/templates/public/javascripts/prototype.js +4320 -0
- data/lib/generators/rails/app/templates/public/javascripts/rails.js +110 -0
- data/lib/generators/rails/app/templates/public/robots.txt +5 -0
- data/lib/generators/rails/app/templates/public/stylesheets/.empty_directory +0 -0
- data/lib/generators/rails/app/templates/script/rails +9 -0
- data/lib/generators/rails/app/templates/test/fixtures/.empty_directory +0 -0
- data/lib/generators/rails/app/templates/test/functional/.empty_directory +0 -0
- data/lib/generators/rails/app/templates/test/integration/.empty_directory +0 -0
- data/lib/generators/rails/app/templates/test/performance/browsing_test.rb +9 -0
- data/lib/generators/rails/app/templates/test/test_helper.rb +13 -0
- data/lib/generators/rails/app/templates/test/unit/.empty_directory +0 -0
- data/lib/generators/rails/controller/USAGE +18 -0
- data/lib/generators/rails/controller/controller_generator.rb +14 -0
- data/lib/generators/rails/controller/templates/controller.rb +7 -0
- data/lib/generators/rails/generator/USAGE +11 -0
- data/lib/generators/rails/generator/generator_generator.rb +25 -0
- data/lib/generators/rails/generator/templates/%file_name%_generator.rb.tt +5 -0
- data/lib/generators/rails/generator/templates/USAGE.tt +8 -0
- data/lib/generators/rails/generator/templates/templates/.empty_directory +0 -0
- data/lib/generators/rails/helper/USAGE +17 -0
- data/lib/generators/rails/helper/helper_generator.rb +13 -0
- data/lib/generators/rails/helper/templates/helper.rb +2 -0
- data/lib/generators/rails/integration_test/USAGE +10 -0
- data/lib/generators/rails/integration_test/integration_test_generator.rb +7 -0
- data/lib/generators/rails/mailer/USAGE +15 -0
- data/lib/generators/rails/mailer/mailer_generator.rb +14 -0
- data/lib/generators/rails/mailer/templates/mailer.rb +16 -0
- data/lib/generators/rails/metal/USAGE +8 -0
- data/lib/generators/rails/metal/metal_generator.rb +11 -0
- data/lib/generators/rails/metal/templates/metal.rb +12 -0
- data/lib/generators/rails/migration/USAGE +29 -0
- data/lib/generators/rails/migration/migration_generator.rb +8 -0
- data/lib/generators/rails/model/USAGE +30 -0
- data/lib/generators/rails/model/model_generator.rb +8 -0
- data/lib/generators/rails/model_subclass/model_subclass_generator.rb +12 -0
- data/lib/generators/rails/observer/USAGE +12 -0
- data/lib/generators/rails/observer/observer_generator.rb +7 -0
- data/lib/generators/rails/performance_test/USAGE +10 -0
- data/lib/generators/rails/performance_test/performance_test_generator.rb +7 -0
- data/lib/generators/rails/plugin/USAGE +13 -0
- data/lib/generators/rails/plugin/plugin_generator.rb +47 -0
- data/lib/generators/rails/plugin/templates/MIT-LICENSE.tt +20 -0
- data/lib/generators/rails/plugin/templates/README.tt +13 -0
- data/lib/generators/rails/plugin/templates/Rakefile.tt +10 -0
- data/lib/generators/rails/plugin/templates/init.rb +1 -0
- data/lib/generators/rails/plugin/templates/install.rb +1 -0
- data/lib/generators/rails/plugin/templates/lib/%file_name%.rb.tt +1 -0
- data/lib/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt +4 -0
- data/lib/generators/rails/plugin/templates/uninstall.rb +1 -0
- data/lib/generators/rails/resource/USAGE +23 -0
- data/lib/generators/rails/resource/resource_generator.rb +34 -0
- data/lib/generators/rails/scaffold/USAGE +29 -0
- data/lib/generators/rails/scaffold/scaffold_generator.rb +13 -0
- data/lib/generators/rails/scaffold_controller/USAGE +20 -0
- data/lib/generators/rails/scaffold_controller/scaffold_controller_generator.rb +27 -0
- data/lib/generators/rails/scaffold_controller/templates/controller.rb +85 -0
- data/lib/generators/rails/session_migration/USAGE +8 -0
- data/lib/generators/rails/session_migration/session_migration_generator.rb +8 -0
- data/lib/generators/rails/stylesheets/USAGE +5 -0
- data/lib/generators/rails/stylesheets/stylesheets_generator.rb +9 -0
- data/lib/generators/rails/stylesheets/templates/scaffold.css +61 -0
- data/lib/generators/test_unit.rb +8 -0
- data/lib/generators/test_unit/controller/controller_generator.rb +14 -0
- data/lib/generators/test_unit/controller/templates/functional_test.rb +8 -0
- data/lib/generators/test_unit/helper/helper_generator.rb +13 -0
- data/lib/generators/test_unit/helper/templates/helper_test.rb +4 -0
- data/lib/generators/test_unit/integration/integration_generator.rb +13 -0
- data/lib/generators/test_unit/integration/templates/integration_test.rb +10 -0
- data/lib/generators/test_unit/mailer/mailer_generator.rb +21 -0
- data/lib/generators/test_unit/mailer/templates/fixture +3 -0
- data/lib/generators/test_unit/mailer/templates/functional_test.rb +22 -0
- data/lib/generators/test_unit/model/model_generator.rb +24 -0
- data/lib/generators/test_unit/model/templates/fixtures.yml +23 -0
- data/lib/generators/test_unit/model/templates/unit_test.rb +8 -0
- data/lib/generators/test_unit/observer/observer_generator.rb +13 -0
- data/lib/generators/test_unit/observer/templates/unit_test.rb +8 -0
- data/lib/generators/test_unit/performance/performance_generator.rb +13 -0
- data/lib/generators/test_unit/performance/templates/performance_test.rb +9 -0
- data/lib/generators/test_unit/plugin/plugin_generator.rb +13 -0
- data/lib/generators/test_unit/plugin/templates/%file_name%_test.rb.tt +8 -0
- data/lib/generators/test_unit/plugin/templates/test_helper.rb +3 -0
- data/lib/generators/test_unit/scaffold/scaffold_generator.rb +18 -0
- data/lib/generators/test_unit/scaffold/templates/functional_test.rb +47 -0
- data/lib/rails.rb +95 -0
- data/lib/rails/all.rb +14 -0
- data/lib/rails/application.rb +125 -0
- data/lib/rails/application/bootstrap.rb +85 -0
- data/lib/rails/application/configurable.rb +19 -0
- data/lib/rails/application/configuration.rb +86 -0
- data/lib/rails/application/finisher.rb +49 -0
- data/lib/rails/application/metal_loader.rb +50 -0
- data/lib/rails/application/railties.rb +31 -0
- data/lib/rails/application/routes_reloader.rb +46 -0
- data/lib/rails/backtrace_cleaner.rb +54 -0
- data/lib/rails/code_statistics.rb +107 -0
- data/lib/rails/commands.rb +72 -0
- data/lib/rails/commands/application.rb +13 -0
- data/lib/rails/commands/console.rb +55 -0
- data/lib/rails/commands/dbconsole.rb +104 -0
- data/lib/rails/commands/destroy.rb +9 -0
- data/lib/rails/commands/generate.rb +9 -0
- data/lib/rails/commands/performance/benchmarker.rb +23 -0
- data/lib/rails/commands/performance/profiler.rb +46 -0
- data/lib/rails/commands/plugin.rb +542 -0
- data/lib/rails/commands/runner.rb +51 -0
- data/lib/rails/commands/server.rb +75 -0
- data/lib/rails/commands/update.rb +9 -0
- data/lib/rails/configuration.rb +191 -0
- data/lib/rails/console/app.rb +33 -0
- data/lib/rails/console/helpers.rb +5 -0
- data/lib/rails/console/sandbox.rb +6 -0
- data/lib/rails/deprecation.rb +62 -0
- data/lib/rails/dispatcher.rb +24 -0
- data/lib/rails/engine.rb +130 -0
- data/lib/rails/engine/configurable.rb +25 -0
- data/lib/rails/engine/configuration.rb +49 -0
- data/lib/rails/generators.rb +289 -0
- data/lib/rails/generators/actions.rb +309 -0
- data/lib/rails/generators/active_model.rb +78 -0
- data/lib/rails/generators/base.rb +362 -0
- data/lib/rails/generators/generated_attribute.rb +48 -0
- data/lib/rails/generators/migration.rb +64 -0
- data/lib/rails/generators/named_base.rb +95 -0
- data/lib/rails/generators/resource_helpers.rb +80 -0
- data/lib/rails/generators/test_case.rb +239 -0
- data/lib/rails/initializable.rb +97 -0
- data/lib/rails/paths.rb +144 -0
- data/lib/rails/performance_test_help.rb +3 -0
- data/lib/rails/plugin.rb +64 -0
- data/lib/rails/rack.rb +8 -0
- data/lib/rails/rack/debugger.rb +23 -0
- data/lib/rails/rack/log_tailer.rb +33 -0
- data/lib/rails/rack/logger.rb +34 -0
- data/lib/rails/rack/static.rb +5 -0
- data/lib/rails/railtie.rb +74 -0
- data/lib/rails/railtie/configurable.rb +23 -0
- data/lib/rails/railtie/configuration.rb +9 -0
- data/lib/rails/railties_path.rb +1 -0
- data/lib/rails/ruby_version_check.rb +10 -0
- data/lib/rails/rubyprof_ext.rb +35 -0
- data/lib/rails/source_annotation_extractor.rb +102 -0
- data/lib/rails/subscriber.rb +108 -0
- data/lib/rails/subscriber/test_helper.rb +98 -0
- data/lib/rails/tasks.rb +16 -0
- data/lib/rails/tasks/annotations.rake +20 -0
- data/lib/rails/tasks/documentation.rake +96 -0
- data/lib/rails/tasks/framework.rake +69 -0
- data/lib/rails/tasks/log.rake +9 -0
- data/lib/rails/tasks/middleware.rake +7 -0
- data/lib/rails/tasks/misc.rake +71 -0
- data/lib/rails/tasks/routes.rake +17 -0
- data/lib/rails/tasks/statistics.rake +16 -0
- data/lib/rails/tasks/tmp.rake +37 -0
- data/lib/rails/test_help.rb +30 -0
- data/lib/rails/test_unit/railtie.rb +17 -0
- data/lib/rails/test_unit/testing.rake +130 -0
- data/lib/rails/version.rb +9 -0
- data/lib/rails/webrick_server.rb +156 -0
- metadata +427 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
require 'open-uri'
|
|
2
|
+
require 'active_support/deprecation'
|
|
3
|
+
|
|
4
|
+
module Rails
|
|
5
|
+
module Generators
|
|
6
|
+
module Actions
|
|
7
|
+
|
|
8
|
+
# Install a plugin. You must provide either a Subversion url or Git url.
|
|
9
|
+
#
|
|
10
|
+
# For a Git-hosted plugin, you can specify a branch and
|
|
11
|
+
# whether it should be added as a submodule instead of cloned.
|
|
12
|
+
#
|
|
13
|
+
# For a Subversion-hosted plugin you can specify a revision.
|
|
14
|
+
#
|
|
15
|
+
# ==== Examples
|
|
16
|
+
#
|
|
17
|
+
# plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git'
|
|
18
|
+
# plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :branch => 'stable'
|
|
19
|
+
# plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :submodule => true
|
|
20
|
+
# plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk'
|
|
21
|
+
# plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk', :revision => 1234
|
|
22
|
+
#
|
|
23
|
+
def plugin(name, options)
|
|
24
|
+
log :plugin, name
|
|
25
|
+
|
|
26
|
+
if options[:git] && options[:submodule]
|
|
27
|
+
options[:git] = "-b #{options[:branch]} #{options[:git]}" if options[:branch]
|
|
28
|
+
in_root do
|
|
29
|
+
run "git submodule add #{options[:git]} vendor/plugins/#{name}", :verbose => false
|
|
30
|
+
end
|
|
31
|
+
elsif options[:git] || options[:svn]
|
|
32
|
+
options[:git] = "-b #{options[:branch]} #{options[:git]}" if options[:branch]
|
|
33
|
+
options[:svn] = "-r #{options[:revision]} #{options[:svn]}" if options[:revision]
|
|
34
|
+
in_root do
|
|
35
|
+
run_ruby_script "script/plugin install #{options[:svn] || options[:git]}", :verbose => false
|
|
36
|
+
end
|
|
37
|
+
else
|
|
38
|
+
log "! no git or svn provided for #{name}. Skipping..."
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Adds an entry into config/environment.rb for the supplied gem. If env
|
|
43
|
+
# is specified, add the gem to the given environment.
|
|
44
|
+
#
|
|
45
|
+
# ==== Example
|
|
46
|
+
#
|
|
47
|
+
# gem "rspec", :env => :test
|
|
48
|
+
# gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/"
|
|
49
|
+
# gem "rails", "3.0", :git => "git://github.com/rails/rails"
|
|
50
|
+
#
|
|
51
|
+
def gem(*args)
|
|
52
|
+
options = args.extract_options!
|
|
53
|
+
name, version = args
|
|
54
|
+
|
|
55
|
+
# Deal with deprecated options
|
|
56
|
+
{ :env => :only, :lib => :require_as }.each do |old, new|
|
|
57
|
+
next unless options[old]
|
|
58
|
+
options[new] = options.delete(old)
|
|
59
|
+
ActiveSupport::Deprecation.warn "#{old.inspect} option in gem is deprecated, use #{new.inspect} instead"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Deal with deprecated source
|
|
63
|
+
if source = options.delete(:source)
|
|
64
|
+
ActiveSupport::Deprecation.warn ":source option in gem is deprecated, use add_source method instead"
|
|
65
|
+
add_source(source)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Set the message to be shown in logs. Uses the git repo if one is given,
|
|
69
|
+
# otherwise use name (version).
|
|
70
|
+
parts, message = [ name.inspect ], name
|
|
71
|
+
if version ||= options.delete(:version)
|
|
72
|
+
parts << version
|
|
73
|
+
message << " (#{version})"
|
|
74
|
+
end
|
|
75
|
+
message = options[:git] if options[:git]
|
|
76
|
+
|
|
77
|
+
log :gemfile, message
|
|
78
|
+
|
|
79
|
+
options.each do |option, value|
|
|
80
|
+
parts << ":#{option} => #{value.inspect}"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
in_root do
|
|
84
|
+
append_file "Gemfile", "gem #{parts.join(", ")}", :verbose => false
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Add the given source to Gemfile
|
|
89
|
+
#
|
|
90
|
+
# ==== Example
|
|
91
|
+
#
|
|
92
|
+
# source "http://gems.github.com/"
|
|
93
|
+
def add_source(source, options={})
|
|
94
|
+
log :source, source
|
|
95
|
+
|
|
96
|
+
in_root do
|
|
97
|
+
prepend_file "Gemfile", "source #{source.inspect}", :verbose => false
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Adds a line inside the Initializer block for config/environment.rb.
|
|
102
|
+
#
|
|
103
|
+
# If options :env is specified, the line is appended to the corresponding
|
|
104
|
+
# file in config/environments.
|
|
105
|
+
#
|
|
106
|
+
def environment(data=nil, options={}, &block)
|
|
107
|
+
sentinel = /class [a-z_:]+ < Rails::Application/i
|
|
108
|
+
data = block.call if !data && block_given?
|
|
109
|
+
|
|
110
|
+
in_root do
|
|
111
|
+
if options[:env].nil?
|
|
112
|
+
inject_into_file 'config/application.rb', "\n #{data}", :after => sentinel, :verbose => false
|
|
113
|
+
else
|
|
114
|
+
Array.wrap(options[:env]).each do|env|
|
|
115
|
+
append_file "config/environments/#{env}.rb", "\n#{data}", :verbose => false
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
alias :application :environment
|
|
121
|
+
|
|
122
|
+
# Run a command in git.
|
|
123
|
+
#
|
|
124
|
+
# ==== Examples
|
|
125
|
+
#
|
|
126
|
+
# git :init
|
|
127
|
+
# git :add => "this.file that.rb"
|
|
128
|
+
# git :add => "onefile.rb", :rm => "badfile.cxx"
|
|
129
|
+
#
|
|
130
|
+
def git(command={})
|
|
131
|
+
if command.is_a?(Symbol)
|
|
132
|
+
run "git #{command}"
|
|
133
|
+
else
|
|
134
|
+
command.each do |command, options|
|
|
135
|
+
run "git #{command} #{options}"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Create a new file in the vendor/ directory. Code can be specified
|
|
141
|
+
# in a block or a data string can be given.
|
|
142
|
+
#
|
|
143
|
+
# ==== Examples
|
|
144
|
+
#
|
|
145
|
+
# vendor("sekrit.rb") do
|
|
146
|
+
# sekrit_salt = "#{Time.now}--#{3.years.ago}--#{rand}--"
|
|
147
|
+
# "salt = '#{sekrit_salt}'"
|
|
148
|
+
# end
|
|
149
|
+
#
|
|
150
|
+
# vendor("foreign.rb", "# Foreign code is fun")
|
|
151
|
+
#
|
|
152
|
+
def vendor(filename, data=nil, &block)
|
|
153
|
+
log :vendor, filename
|
|
154
|
+
create_file("vendor/#{filename}", data, :verbose => false, &block)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Create a new file in the lib/ directory. Code can be specified
|
|
158
|
+
# in a block or a data string can be given.
|
|
159
|
+
#
|
|
160
|
+
# ==== Examples
|
|
161
|
+
#
|
|
162
|
+
# lib("crypto.rb") do
|
|
163
|
+
# "crypted_special_value = '#{rand}--#{Time.now}--#{rand(1337)}--'"
|
|
164
|
+
# end
|
|
165
|
+
#
|
|
166
|
+
# lib("foreign.rb", "# Foreign code is fun")
|
|
167
|
+
#
|
|
168
|
+
def lib(filename, data=nil, &block)
|
|
169
|
+
log :lib, filename
|
|
170
|
+
create_file("lib/#{filename}", data, :verbose => false, &block)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Create a new Rakefile with the provided code (either in a block or a string).
|
|
174
|
+
#
|
|
175
|
+
# ==== Examples
|
|
176
|
+
#
|
|
177
|
+
# rakefile("bootstrap.rake") do
|
|
178
|
+
# project = ask("What is the UNIX name of your project?")
|
|
179
|
+
#
|
|
180
|
+
# <<-TASK
|
|
181
|
+
# namespace :#{project} do
|
|
182
|
+
# task :bootstrap do
|
|
183
|
+
# puts "i like boots!"
|
|
184
|
+
# end
|
|
185
|
+
# end
|
|
186
|
+
# TASK
|
|
187
|
+
# end
|
|
188
|
+
#
|
|
189
|
+
# rakefile("seed.rake", "puts 'im plantin ur seedz'")
|
|
190
|
+
#
|
|
191
|
+
def rakefile(filename, data=nil, &block)
|
|
192
|
+
log :rakefile, filename
|
|
193
|
+
create_file("lib/tasks/#{filename}", data, :verbose => false, &block)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Create a new initializer with the provided code (either in a block or a string).
|
|
197
|
+
#
|
|
198
|
+
# ==== Examples
|
|
199
|
+
#
|
|
200
|
+
# initializer("globals.rb") do
|
|
201
|
+
# data = ""
|
|
202
|
+
#
|
|
203
|
+
# ['MY_WORK', 'ADMINS', 'BEST_COMPANY_EVAR'].each do
|
|
204
|
+
# data << "#{const} = :entp"
|
|
205
|
+
# end
|
|
206
|
+
#
|
|
207
|
+
# data
|
|
208
|
+
# end
|
|
209
|
+
#
|
|
210
|
+
# initializer("api.rb", "API_KEY = '123456'")
|
|
211
|
+
#
|
|
212
|
+
def initializer(filename, data=nil, &block)
|
|
213
|
+
log :initializer, filename
|
|
214
|
+
create_file("config/initializers/#{filename}", data, :verbose => false, &block)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# Generate something using a generator from Rails or a plugin.
|
|
218
|
+
# The second parameter is the argument string that is passed to
|
|
219
|
+
# the generator or an Array that is joined.
|
|
220
|
+
#
|
|
221
|
+
# ==== Example
|
|
222
|
+
#
|
|
223
|
+
# generate(:authenticated, "user session")
|
|
224
|
+
#
|
|
225
|
+
def generate(what, *args)
|
|
226
|
+
log :generate, what
|
|
227
|
+
argument = args.map {|arg| arg.to_s }.flatten.join(" ")
|
|
228
|
+
|
|
229
|
+
in_root { run_ruby_script("script/generate #{what} #{argument}", :verbose => false) }
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Runs the supplied rake task
|
|
233
|
+
#
|
|
234
|
+
# ==== Example
|
|
235
|
+
#
|
|
236
|
+
# rake("db:migrate")
|
|
237
|
+
# rake("db:migrate", :env => "production")
|
|
238
|
+
# rake("gems:install", :sudo => true)
|
|
239
|
+
#
|
|
240
|
+
def rake(command, options={})
|
|
241
|
+
log :rake, command
|
|
242
|
+
env = options[:env] || 'development'
|
|
243
|
+
sudo = options[:sudo] && RUBY_PLATFORM !~ /mswin|mingw/ ? 'sudo ' : ''
|
|
244
|
+
in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) }
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Just run the capify command in root
|
|
248
|
+
#
|
|
249
|
+
# ==== Example
|
|
250
|
+
#
|
|
251
|
+
# capify!
|
|
252
|
+
#
|
|
253
|
+
def capify!
|
|
254
|
+
log :capify, ""
|
|
255
|
+
in_root { run("#{extify(:capify)} .", :verbose => false) }
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
# Add Rails to /vendor/rails
|
|
259
|
+
#
|
|
260
|
+
# ==== Example
|
|
261
|
+
#
|
|
262
|
+
# freeze!
|
|
263
|
+
#
|
|
264
|
+
def freeze!(args={})
|
|
265
|
+
ActiveSupport::Deprecation.warn "freeze! is deprecated since your rails app now comes bundled with Rails by default, please check your Gemfile"
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# Make an entry in Rails routing file conifg/routes.rb
|
|
269
|
+
#
|
|
270
|
+
# === Example
|
|
271
|
+
#
|
|
272
|
+
# route "root :to => 'welcome'"
|
|
273
|
+
#
|
|
274
|
+
def route(routing_code)
|
|
275
|
+
log :route, routing_code
|
|
276
|
+
sentinel = "routes.draw do |map|"
|
|
277
|
+
|
|
278
|
+
in_root do
|
|
279
|
+
inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false }
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
protected
|
|
284
|
+
|
|
285
|
+
# Define log for backwards compatibility. If just one argument is sent,
|
|
286
|
+
# invoke say, otherwise invoke say_status.
|
|
287
|
+
#
|
|
288
|
+
def log(*args)
|
|
289
|
+
if args.size == 1
|
|
290
|
+
say args.first.to_s
|
|
291
|
+
else
|
|
292
|
+
args << (self.behavior == :invoke ? :green : :red)
|
|
293
|
+
say_status *args
|
|
294
|
+
end
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
# Add an extension to the given name based on the platform.
|
|
298
|
+
#
|
|
299
|
+
def extify(name)
|
|
300
|
+
if RUBY_PLATFORM =~ /mswin|mingw/
|
|
301
|
+
"#{name}.bat"
|
|
302
|
+
else
|
|
303
|
+
name
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module Rails
|
|
2
|
+
module Generators
|
|
3
|
+
# ActiveModel is a class to be implemented by each ORM to allow Rails to
|
|
4
|
+
# generate customized controller code.
|
|
5
|
+
#
|
|
6
|
+
# The API has the same methods as ActiveRecord, but each method returns a
|
|
7
|
+
# string that matches the ORM API.
|
|
8
|
+
#
|
|
9
|
+
# For example:
|
|
10
|
+
#
|
|
11
|
+
# ActiveRecord::Generators::ActiveModel.find(Foo, "params[:id]")
|
|
12
|
+
# #=> "Foo.find(params[:id])"
|
|
13
|
+
#
|
|
14
|
+
# Datamapper::Generators::ActiveModel.find(Foo, "params[:id]")
|
|
15
|
+
# #=> "Foo.get(params[:id])"
|
|
16
|
+
#
|
|
17
|
+
# On initialization, the ActiveModel accepts the instance name that will
|
|
18
|
+
# receive the calls:
|
|
19
|
+
#
|
|
20
|
+
# builder = ActiveRecord::Generators::ActiveModel.new "@foo"
|
|
21
|
+
# builder.save #=> "@foo.save"
|
|
22
|
+
#
|
|
23
|
+
# The only exception in ActiveModel for ActiveRecord is the use of self.build
|
|
24
|
+
# instead of self.new.
|
|
25
|
+
#
|
|
26
|
+
class ActiveModel
|
|
27
|
+
attr_reader :name
|
|
28
|
+
|
|
29
|
+
def initialize(name)
|
|
30
|
+
@name = name
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# GET index
|
|
34
|
+
def self.all(klass)
|
|
35
|
+
"#{klass}.all"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# GET show
|
|
39
|
+
# GET edit
|
|
40
|
+
# PUT update
|
|
41
|
+
# DELETE destroy
|
|
42
|
+
def self.find(klass, params=nil)
|
|
43
|
+
"#{klass}.find(#{params})"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# GET new
|
|
47
|
+
# POST create
|
|
48
|
+
def self.build(klass, params=nil)
|
|
49
|
+
if params
|
|
50
|
+
"#{klass}.new(#{params})"
|
|
51
|
+
else
|
|
52
|
+
"#{klass}.new"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# POST create
|
|
57
|
+
def save
|
|
58
|
+
"#{name}.save"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# PUT update
|
|
62
|
+
def update_attributes(params=nil)
|
|
63
|
+
"#{name}.update_attributes(#{params})"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# POST create
|
|
67
|
+
# PUT update
|
|
68
|
+
def errors
|
|
69
|
+
"#{name}.errors"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# DELETE destroy
|
|
73
|
+
def destroy
|
|
74
|
+
"#{name}.destroy"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
require 'thor/group'
|
|
2
|
+
require 'rails/generators/actions'
|
|
3
|
+
|
|
4
|
+
module Rails
|
|
5
|
+
module Generators
|
|
6
|
+
class Error < Thor::Error
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class Base < Thor::Group
|
|
10
|
+
include Thor::Actions
|
|
11
|
+
include Rails::Generators::Actions
|
|
12
|
+
|
|
13
|
+
add_runtime_options!
|
|
14
|
+
|
|
15
|
+
# Automatically sets the source root based on the class name.
|
|
16
|
+
#
|
|
17
|
+
def self.source_root
|
|
18
|
+
@_rails_source_root ||= begin
|
|
19
|
+
if base_name && generator_name
|
|
20
|
+
File.expand_path(File.join("../../generators", base_name, generator_name, 'templates'), File.dirname(__FILE__))
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Tries to get the description from a USAGE file one folder above the source
|
|
26
|
+
# root otherwise uses a default description.
|
|
27
|
+
#
|
|
28
|
+
def self.desc(description=nil)
|
|
29
|
+
return super if description
|
|
30
|
+
usage = File.expand_path(File.join(source_root, "..", "USAGE"))
|
|
31
|
+
|
|
32
|
+
@desc ||= if File.exist?(usage)
|
|
33
|
+
File.read(usage)
|
|
34
|
+
else
|
|
35
|
+
"Description:\n Create #{base_name.humanize.downcase} files for #{generator_name} generator."
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Convenience method to get the namespace from the class name. It's the
|
|
40
|
+
# same as Thor default except that the Generator at the end of the class
|
|
41
|
+
# is removed.
|
|
42
|
+
#
|
|
43
|
+
def self.namespace(name=nil)
|
|
44
|
+
return super if name
|
|
45
|
+
@namespace ||= super.sub(/_generator$/, '').sub(/:generators:/, ':')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Invoke a generator based on the value supplied by the user to the
|
|
49
|
+
# given option named "name". A class option is created when this method
|
|
50
|
+
# is invoked and you can set a hash to customize it.
|
|
51
|
+
#
|
|
52
|
+
# ==== Examples
|
|
53
|
+
#
|
|
54
|
+
# module Rails::Generators
|
|
55
|
+
# class ControllerGenerator < Base
|
|
56
|
+
# hook_for :test_framework, :aliases => "-t"
|
|
57
|
+
# end
|
|
58
|
+
# end
|
|
59
|
+
#
|
|
60
|
+
# The example above will create a test framework option and will invoke
|
|
61
|
+
# a generator based on the user supplied value.
|
|
62
|
+
#
|
|
63
|
+
# For example, if the user invoke the controller generator as:
|
|
64
|
+
#
|
|
65
|
+
# ruby script/generate controller Account --test-framework=test_unit
|
|
66
|
+
#
|
|
67
|
+
# The controller generator will then try to invoke the following generators:
|
|
68
|
+
#
|
|
69
|
+
# "rails:test_unit", "test_unit:controller", "test_unit"
|
|
70
|
+
#
|
|
71
|
+
# Notice that "rails:generators:test_unit" could be loaded as well, what
|
|
72
|
+
# Rails looks for is the first and last parts of the namespace. This is what
|
|
73
|
+
# allows any test framework to hook into Rails as long as it provides any
|
|
74
|
+
# of the hooks above.
|
|
75
|
+
#
|
|
76
|
+
# ==== Options
|
|
77
|
+
#
|
|
78
|
+
# The first and last part used to find the generator to be invoked are
|
|
79
|
+
# guessed based on class invokes hook_for, as noticed in the example above.
|
|
80
|
+
# This can be customized with two options: :base and :as.
|
|
81
|
+
#
|
|
82
|
+
# Let's suppose you are creating a generator that needs to invoke the
|
|
83
|
+
# controller generator from test unit. Your first attempt is:
|
|
84
|
+
#
|
|
85
|
+
# class AwesomeGenerator < Rails::Generators::Base
|
|
86
|
+
# hook_for :test_framework
|
|
87
|
+
# end
|
|
88
|
+
#
|
|
89
|
+
# The lookup in this case for test_unit as input is:
|
|
90
|
+
#
|
|
91
|
+
# "test_unit:awesome", "test_unit"
|
|
92
|
+
#
|
|
93
|
+
# Which is not the desired the lookup. You can change it by providing the
|
|
94
|
+
# :as option:
|
|
95
|
+
#
|
|
96
|
+
# class AwesomeGenerator < Rails::Generators::Base
|
|
97
|
+
# hook_for :test_framework, :as => :controller
|
|
98
|
+
# end
|
|
99
|
+
#
|
|
100
|
+
# And now it will lookup at:
|
|
101
|
+
#
|
|
102
|
+
# "test_unit:controller", "test_unit"
|
|
103
|
+
#
|
|
104
|
+
# Similarly, if you want it to also lookup in the rails namespace, you just
|
|
105
|
+
# need to provide the :base value:
|
|
106
|
+
#
|
|
107
|
+
# class AwesomeGenerator < Rails::Generators::Base
|
|
108
|
+
# hook_for :test_framework, :in => :rails, :as => :controller
|
|
109
|
+
# end
|
|
110
|
+
#
|
|
111
|
+
# And the lookup is exactly the same as previously:
|
|
112
|
+
#
|
|
113
|
+
# "rails:test_unit", "test_unit:controller", "test_unit"
|
|
114
|
+
#
|
|
115
|
+
# ==== Switches
|
|
116
|
+
#
|
|
117
|
+
# All hooks come with switches for user interface. If the user don't want
|
|
118
|
+
# to use any test framework, he can do:
|
|
119
|
+
#
|
|
120
|
+
# ruby script/generate controller Account --skip-test-framework
|
|
121
|
+
#
|
|
122
|
+
# Or similarly:
|
|
123
|
+
#
|
|
124
|
+
# ruby script/generate controller Account --no-test-framework
|
|
125
|
+
#
|
|
126
|
+
# ==== Boolean hooks
|
|
127
|
+
#
|
|
128
|
+
# In some cases, you want to provide a boolean hook. For example, webrat
|
|
129
|
+
# developers might want to have webrat available on controller generator.
|
|
130
|
+
# This can be achieved as:
|
|
131
|
+
#
|
|
132
|
+
# Rails::Generators::ControllerGenerator.hook_for :webrat, :type => :boolean
|
|
133
|
+
#
|
|
134
|
+
# Then, if you want, webrat to be invoked, just supply:
|
|
135
|
+
#
|
|
136
|
+
# ruby script/generate controller Account --webrat
|
|
137
|
+
#
|
|
138
|
+
# The hooks lookup is similar as above:
|
|
139
|
+
#
|
|
140
|
+
# "rails:generators:webrat", "webrat:generators:controller", "webrat"
|
|
141
|
+
#
|
|
142
|
+
# ==== Custom invocations
|
|
143
|
+
#
|
|
144
|
+
# You can also supply a block to hook_for to customize how the hook is
|
|
145
|
+
# going to be invoked. The block receives two arguments, an instance
|
|
146
|
+
# of the current class and the klass to be invoked.
|
|
147
|
+
#
|
|
148
|
+
# For example, in the resource generator, the controller should be invoked
|
|
149
|
+
# with a pluralized class name. But by default it is invoked with the same
|
|
150
|
+
# name as the resource generator, which is singular. To change this, we
|
|
151
|
+
# can give a block to customize how the controller can be invoked.
|
|
152
|
+
#
|
|
153
|
+
# hook_for :resource_controller do |instance, controller|
|
|
154
|
+
# instance.invoke controller, [ instance.name.pluralize ]
|
|
155
|
+
# end
|
|
156
|
+
#
|
|
157
|
+
def self.hook_for(*names, &block)
|
|
158
|
+
options = names.extract_options!
|
|
159
|
+
in_base = options.delete(:in) || base_name
|
|
160
|
+
as_hook = options.delete(:as) || generator_name
|
|
161
|
+
|
|
162
|
+
names.each do |name|
|
|
163
|
+
defaults = if options[:type] == :boolean
|
|
164
|
+
{ }
|
|
165
|
+
elsif [true, false].include?(default_value_for_option(name, options))
|
|
166
|
+
{ :banner => "" }
|
|
167
|
+
else
|
|
168
|
+
{ :desc => "#{name.to_s.humanize} to be invoked", :banner => "NAME" }
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
unless class_options.key?(name)
|
|
172
|
+
class_option(name, defaults.merge!(options))
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
hooks[name] = [ in_base, as_hook ]
|
|
176
|
+
invoke_from_option(name, options, &block)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Remove a previously added hook.
|
|
181
|
+
#
|
|
182
|
+
# ==== Examples
|
|
183
|
+
#
|
|
184
|
+
# remove_hook_for :orm
|
|
185
|
+
#
|
|
186
|
+
def self.remove_hook_for(*names)
|
|
187
|
+
remove_invocation(*names)
|
|
188
|
+
|
|
189
|
+
names.each do |name|
|
|
190
|
+
hooks.delete(name)
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Make class option aware of Rails::Generators.options and Rails::Generators.aliases.
|
|
195
|
+
#
|
|
196
|
+
def self.class_option(name, options={}) #:nodoc:
|
|
197
|
+
options[:desc] = "Indicates when to generate #{name.to_s.humanize.downcase}" unless options.key?(:desc)
|
|
198
|
+
options[:aliases] = default_aliases_for_option(name, options)
|
|
199
|
+
options[:default] = default_value_for_option(name, options)
|
|
200
|
+
super(name, options)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# Cache source root and add lib/generators/base/generator/templates to
|
|
204
|
+
# source paths.
|
|
205
|
+
#
|
|
206
|
+
def self.inherited(base) #:nodoc:
|
|
207
|
+
super
|
|
208
|
+
|
|
209
|
+
# Cache source root, we need to do this, since __FILE__ is a relative value
|
|
210
|
+
# and can point to wrong directions when inside an specified directory.
|
|
211
|
+
base.source_root
|
|
212
|
+
|
|
213
|
+
if base.name && base.name !~ /Base$/
|
|
214
|
+
Rails::Generators.subclasses << base
|
|
215
|
+
|
|
216
|
+
if defined?(Rails.root) && Rails.root
|
|
217
|
+
path = File.expand_path(File.join(Rails.root, 'lib', 'templates'))
|
|
218
|
+
if base.name.include?('::')
|
|
219
|
+
base.source_paths << File.join(path, base.base_name, base.generator_name)
|
|
220
|
+
else
|
|
221
|
+
base.source_paths << File.join(path, base.generator_name)
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
protected
|
|
228
|
+
|
|
229
|
+
# Check whether the given class names are already taken by user
|
|
230
|
+
# application or Ruby on Rails.
|
|
231
|
+
#
|
|
232
|
+
def class_collisions(*class_names) #:nodoc:
|
|
233
|
+
return unless behavior == :invoke
|
|
234
|
+
|
|
235
|
+
class_names.flatten.each do |class_name|
|
|
236
|
+
class_name = class_name.to_s
|
|
237
|
+
next if class_name.strip.empty?
|
|
238
|
+
|
|
239
|
+
# Split the class from its module nesting
|
|
240
|
+
nesting = class_name.split('::')
|
|
241
|
+
last_name = nesting.pop
|
|
242
|
+
|
|
243
|
+
# Hack to limit const_defined? to non-inherited on 1.9
|
|
244
|
+
extra = []
|
|
245
|
+
extra << false unless Object.method(:const_defined?).arity == 1
|
|
246
|
+
|
|
247
|
+
# Extract the last Module in the nesting
|
|
248
|
+
last = nesting.inject(Object) do |last, nest|
|
|
249
|
+
break unless last.const_defined?(nest, *extra)
|
|
250
|
+
last.const_get(nest)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
if last && last.const_defined?(last_name.camelize, *extra)
|
|
254
|
+
raise Error, "The name '#{class_name}' is either already used in your application " <<
|
|
255
|
+
"or reserved by Ruby on Rails. Please choose an alternative and run " <<
|
|
256
|
+
"this generator again."
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
# Use Rails default banner.
|
|
262
|
+
#
|
|
263
|
+
def self.banner
|
|
264
|
+
"rails generate #{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
# Sets the base_name taking into account the current class namespace.
|
|
268
|
+
#
|
|
269
|
+
def self.base_name
|
|
270
|
+
@base_name ||= begin
|
|
271
|
+
if base = name.to_s.split('::').first
|
|
272
|
+
base.underscore
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
# Removes the namespaces and get the generator name. For example,
|
|
278
|
+
# Rails::Generators::MetalGenerator will return "metal" as generator name.
|
|
279
|
+
#
|
|
280
|
+
def self.generator_name
|
|
281
|
+
@generator_name ||= begin
|
|
282
|
+
if generator = name.to_s.split('::').last
|
|
283
|
+
generator.sub!(/Generator$/, '')
|
|
284
|
+
generator.underscore
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Return the default value for the option name given doing a lookup in
|
|
290
|
+
# Rails::Generators.options.
|
|
291
|
+
#
|
|
292
|
+
def self.default_value_for_option(name, options)
|
|
293
|
+
default_for_option(Rails::Generators.options, name, options, options[:default])
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
# Return default aliases for the option name given doing a lookup in
|
|
297
|
+
# Rails::Generators.aliases.
|
|
298
|
+
#
|
|
299
|
+
def self.default_aliases_for_option(name, options)
|
|
300
|
+
default_for_option(Rails::Generators.aliases, name, options, options[:aliases])
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
# Return default for the option name given doing a lookup in config.
|
|
304
|
+
#
|
|
305
|
+
def self.default_for_option(config, name, options, default)
|
|
306
|
+
if generator_name and c = config[generator_name.to_sym] and c.key?(name)
|
|
307
|
+
c[name]
|
|
308
|
+
elsif base_name and c = config[base_name.to_sym] and c.key?(name)
|
|
309
|
+
c[name]
|
|
310
|
+
elsif config[:rails].key?(name)
|
|
311
|
+
config[:rails][name]
|
|
312
|
+
else
|
|
313
|
+
default
|
|
314
|
+
end
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# Keep hooks configuration that are used on prepare_for_invocation.
|
|
318
|
+
#
|
|
319
|
+
def self.hooks #:nodoc:
|
|
320
|
+
@hooks ||= from_superclass(:hooks, {})
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Prepare class invocation to search on Rails namespace if a previous
|
|
324
|
+
# added hook is being used.
|
|
325
|
+
#
|
|
326
|
+
def self.prepare_for_invocation(name, value) #:nodoc:
|
|
327
|
+
return super unless value.is_a?(String) || value.is_a?(Symbol)
|
|
328
|
+
|
|
329
|
+
if value && constants = self.hooks[name]
|
|
330
|
+
value = name if TrueClass === value
|
|
331
|
+
Rails::Generators.find_by_namespace(value, *constants)
|
|
332
|
+
elsif klass = Rails::Generators.find_by_namespace(value)
|
|
333
|
+
klass
|
|
334
|
+
else
|
|
335
|
+
super
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
# Small macro to add ruby as an option to the generator with proper
|
|
340
|
+
# default value plus an instance helper method called shebang.
|
|
341
|
+
#
|
|
342
|
+
def self.add_shebang_option!
|
|
343
|
+
class_option :ruby, :type => :string, :aliases => "-r", :default => Thor::Util.ruby_command,
|
|
344
|
+
:desc => "Path to the Ruby binary of your choice", :banner => "PATH"
|
|
345
|
+
|
|
346
|
+
no_tasks {
|
|
347
|
+
define_method :shebang do
|
|
348
|
+
@shebang ||= begin
|
|
349
|
+
command = if options[:ruby] == Thor::Util.ruby_command
|
|
350
|
+
"/usr/bin/env #{File.basename(Thor::Util.ruby_command)}"
|
|
351
|
+
else
|
|
352
|
+
options[:ruby]
|
|
353
|
+
end
|
|
354
|
+
"#!#{command}"
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
}
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
end
|