mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Load generators from user home and show a error message if they can't be loaded.
This commit is contained in:
parent
b277cf28e8
commit
eeb6a0786a
3 changed files with 37 additions and 11 deletions
|
@ -1,27 +1,39 @@
|
|||
activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
|
||||
$:.unshift(activesupport_path) if File.directory?(activesupport_path)
|
||||
|
||||
begin
|
||||
require 'active_support/all'
|
||||
rescue LoadError
|
||||
require 'rubygems'
|
||||
gem 'activesupport'
|
||||
require 'active_support/all'
|
||||
end
|
||||
|
||||
$:.unshift(File.dirname(__FILE__))
|
||||
require 'rails/version' unless defined?(Rails::VERSION)
|
||||
|
||||
# TODO Use vendored Thor
|
||||
require 'rubygems'
|
||||
gem 'josevalim-thor'
|
||||
require 'thor'
|
||||
|
||||
$:.unshift(File.dirname(__FILE__))
|
||||
require 'rails/version' unless defined?(Rails::VERSION)
|
||||
|
||||
require 'generators/base'
|
||||
require 'generators/named_base'
|
||||
|
||||
module Rails
|
||||
module Generators
|
||||
|
||||
# Generators load paths. First search on generators in the RAILS_ROOT, then
|
||||
# look for them in rails generators.
|
||||
# Generators load paths used on lookup. The lookup happens as:
|
||||
#
|
||||
# TODO Right now, only plugin and frozen gems generators are loaded. Gems
|
||||
# loaded by rubygems are not available since Rails dependencies system is
|
||||
# being reworked.
|
||||
# 1) builtin generators
|
||||
# 2) frozen gems generators
|
||||
# 3) rubygems gems generators (not available yet)
|
||||
# 4) plugin generators
|
||||
# 5) lib generators
|
||||
# 6) ~/rails/generators
|
||||
#
|
||||
# TODO Add Rubygems generators (depends on dependencies system rework)
|
||||
# TODO Remove hardcoded paths for all, except (1).
|
||||
#
|
||||
def self.load_path
|
||||
@@load_path ||= begin
|
||||
|
@ -32,6 +44,7 @@ module Rails
|
|||
paths += Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")]
|
||||
paths << File.join(RAILS_ROOT, "lib", "generators")
|
||||
end
|
||||
paths << File.join(Thor::Util.user_home, ".rails", "generators")
|
||||
paths
|
||||
end
|
||||
end
|
||||
|
@ -174,7 +187,11 @@ module Rails
|
|||
|
||||
self.load_path.each do |path|
|
||||
Dir[File.join(path, generators_path, name)].each do |file|
|
||||
begin
|
||||
require file
|
||||
rescue Exception => e
|
||||
warn "[WARNING] Could not load generator at #{file.inspect}. Error: #{e.message}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
3
railties/test/fixtures/vendor/gems/wrong/lib/generators/wrong_generator.rb
vendored
Normal file
3
railties/test/fixtures/vendor/gems/wrong/lib/generators/wrong_generator.rb
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Old generator version
|
||||
class WrongGenerator < Rails::Generator::NamedBase
|
||||
end
|
|
@ -81,7 +81,13 @@ class GeneratorsTest < GeneratorsTestCase
|
|||
|
||||
def test_rails_generators_with_others_information
|
||||
output = capture(:stdout){ Rails::Generators.help }.split("\n").last
|
||||
assert_equal "Others: active_record:fixjour, fixjour, mspec, rails:javascripts.", output
|
||||
assert_equal "Others: active_record:fixjour, fixjour, mspec, rails:javascripts, wrong.", output
|
||||
end
|
||||
|
||||
def test_warning_is_raised_if_generator_cant_be_loaded
|
||||
output = capture(:stderr){ Rails::Generators.find_by_namespace(:wrong) }
|
||||
assert_match /\[WARNING\] Could not load generator at/, output
|
||||
assert_match /Error: uninitialized constant Rails::Generator/, output
|
||||
end
|
||||
|
||||
def test_no_color_sets_proper_shell
|
||||
|
|
Loading…
Reference in a new issue