aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/generators.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-08-08 12:12:56 +0200
committerJosé Valim <jose.valim@gmail.com>2009-08-08 17:48:07 +0200
commit016ed9b4298d187182d05340baddbe98f4eb8fb5 (patch)
treebcffe454a60cb95b2e85856e67d96b01f0704e6a /railties/lib/generators.rb
parent469d89dd442dc8590575daad4ae9052c229c917f (diff)
downloadrails-016ed9b4298d187182d05340baddbe98f4eb8fb5.tar.gz
rails-016ed9b4298d187182d05340baddbe98f4eb8fb5.tar.bz2
rails-016ed9b4298d187182d05340baddbe98f4eb8fb5.zip
Added rubygems to generators load_paths, but we only load generators from gems that are alraedy activated. This fixes the version problem and avoid silly conflicts.
Diffstat (limited to 'railties/lib/generators.rb')
-rw-r--r--railties/lib/generators.rb64
1 files changed, 43 insertions, 21 deletions
diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb
index ef837e1488..c97c61507a 100644
--- a/railties/lib/generators.rb
+++ b/railties/lib/generators.rb
@@ -83,6 +83,34 @@ module Rails
@@options ||= DEFAULT_OPTIONS.dup
end
+ # Get paths only from loaded rubygems. In other words, to use rspec
+ # generators, you first have to ensure that rspec gem was already loaded.
+ #
+ def self.rubygems_generators_paths
+ paths = []
+ return paths unless defined?(Gem)
+
+ Gem.loaded_specs.each do |name, spec|
+ generator_path = File.join(spec.full_gem_path, "lib/generators")
+ paths << generator_path if File.exist?(generator_path)
+ end
+
+ paths
+ end
+
+ # If RAILS_ROOT is defined, add vendor/gems, vendor/plugins and lib/generators
+ # paths.
+ #
+ def self.rails_root_generators_paths
+ paths = []
+ if defined?(RAILS_ROOT)
+ paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "gems", "*", "lib", "generators")]
+ paths += Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")]
+ paths << File.join(RAILS_ROOT, "lib", "generators")
+ end
+ paths
+ end
+
# Hold configured generators fallbacks. If a plugin developer wants a
# generator group to fallback to another group in case of missing generators,
# they can add a fallback.
@@ -108,30 +136,25 @@ module Rails
# Generators load paths used on lookup. The lookup happens as:
#
- # 1) builtin generators
- # 2) frozen gems generators
- # 3) rubygems gems generators (not available yet)
- # 4) plugin generators
- # 5) lib generators
- # 6) ~/rails/generators
+ # 1) lib generators
+ # 2) vendor/plugin generators
+ # 3) vendor/gems generators
+ # 4) ~/rails/generators
+ # 5) rubygems generators
+ # 6) builtin 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
- paths = []
- paths << File.expand_path(File.join(File.dirname(__FILE__), "generators"))
- if defined?(RAILS_ROOT)
- paths += Dir[File.join(RAILS_ROOT, "vendor", "gems", "*", "lib", "generators")]
- paths += Dir[File.join(RAILS_ROOT, "vendor", "plugins", "*", "lib", "generators")]
- paths << File.join(RAILS_ROOT, "lib", "generators")
- end
+ def self.load_paths
+ @@load_paths ||= begin
+ paths = self.rails_root_generators_paths
paths << File.join(Thor::Util.user_home, ".rails", "generators")
+ paths += self.rubygems_generators_paths
+ paths << File.expand_path(File.join(File.dirname(__FILE__), "generators"))
paths
end
end
- load_path # Cache load paths. Needed to avoid __FILE__ pointing to wrong paths.
+ load_paths # Cache load paths. Needed to avoid __FILE__ pointing to wrong paths.
# Receives a namespace and tries different combinations to find a generator.
#
@@ -204,8 +227,8 @@ module Rails
puts "Builtin: #{rails.join(', ')}."
# Load paths and remove builtin
- paths, others = load_path.dup, []
- paths.shift
+ paths, others = load_paths.dup, []
+ paths.pop
paths.each do |path|
tail = [ "*", "*", "*_generator.rb" ]
@@ -242,7 +265,6 @@ module Rails
#
def self.invoke_fallbacks_for(name, base)
return nil unless base && fallbacks[base.to_sym]
-
invoked_fallbacks = []
Array(fallbacks[base.to_sym]).each do |fallback|
@@ -283,7 +305,7 @@ module Rails
generators_path.uniq!
generators_path = "{#{generators_path.join(',')}}"
- self.load_path.each do |path|
+ self.load_paths.each do |path|
Dir[File.join(path, generators_path, name)].each do |file|
begin
require file