aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/application.rb6
-rw-r--r--railties/lib/rails/generators.rb38
-rw-r--r--railties/lib/rails/plugin.rb2
-rw-r--r--railties/lib/rails/railtie.rb15
-rw-r--r--railties/lib/rails/subscriber.rb6
-rw-r--r--railties/lib/rails/tasks/middleware.rake2
6 files changed, 51 insertions, 18 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 4d05f8115c..b92a7ff129 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -8,7 +8,7 @@ module Rails
class << self
attr_writer :config
alias configure class_eval
- delegate :initialize!, :load_tasks, :root, :to => :instance
+ delegate :initialize!, :load_tasks, :load_generators, :root, :to => :instance
private :new
def instance
@@ -82,6 +82,10 @@ module Rails
end
end
+ def load_generators
+ plugins.each { |p| p.load_generators }
+ end
+
def initializers
initializers = Bootstrap.new(self).initializers
plugins.each { |p| initializers += p.initializers }
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 736c36c0dc..d3175e6a9d 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -168,7 +168,7 @@ module Rails
# Show help message with available generators.
def self.help
- traverse_load_paths!
+ lookup!
namespaces = subclasses.map{ |k| k.namespace }
namespaces.sort!
@@ -226,22 +226,10 @@ module Rails
nil
end
- # This will try to load any generator in the load path to show in help.
- def self.traverse_load_paths! #:nodoc:
- $LOAD_PATH.each do |base|
- Dir[File.join(base, "{generators,rails_generators}", "**", "*_generator.rb")].each do |path|
- begin
- require path
- rescue Exception => e
- # No problem
- end
- end
- end
- end
-
# Receives namespaces in an array and tries to find matching generators
# in the load path.
def self.lookup(namespaces) #:nodoc:
+ load_generators_from_railties!
paths = namespaces_to_paths(namespaces)
paths.each do |path|
@@ -261,6 +249,28 @@ module Rails
end
end
+ # This will try to load any generator in the load path to show in help.
+ def self.lookup! #:nodoc:
+ load_generators_from_railties!
+
+ $LOAD_PATH.each do |base|
+ Dir[File.join(base, "{generators,rails_generators}", "**", "*_generator.rb")].each do |path|
+ begin
+ require path
+ rescue Exception => e
+ # No problem
+ end
+ end
+ end
+ end
+
+ # Allow generators to be loaded from custom paths.
+ def self.load_generators_from_railties! #:nodoc:
+ return if defined?(@generators_from_railties) || Rails.application.nil?
+ @generators_from_railties = true
+ Rails.application.load_generators
+ end
+
# Convert namespaces to paths by replacing ":" for "/" and adding
# an extra lookup. For example, "rails:model" should be searched
# in both: "rails/model/model_generator" and "rails/model_generator".
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index 0c09730963..c3b81bcd3e 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -27,7 +27,7 @@ module Rails
end
def load_tasks
- Dir["#{path}/**/tasks/**/*.rake"].sort.each { |ext| load ext }
+ Dir["#{path}/{tasks,lib/tasks,rails/tasks}/**/*.rake"].sort.each { |ext| load ext }
end
initializer :add_to_load_path, :after => :set_autoload_paths do |app|
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb
index 43a0303c5b..e3297148e5 100644
--- a/railties/lib/rails/railtie.rb
+++ b/railties/lib/rails/railtie.rb
@@ -35,13 +35,28 @@ module Rails
@rake_tasks
end
+ def self.generators(&blk)
+ @generators ||= []
+ @generators << blk if blk
+ @generators
+ end
+
def rake_tasks
self.class.rake_tasks
end
+ def generators
+ self.class.generators
+ end
+
def load_tasks
return unless rake_tasks
rake_tasks.each { |blk| blk.call }
end
+
+ def load_generators
+ return unless generators
+ generators.each { |blk| blk.call }
+ end
end
end
diff --git a/railties/lib/rails/subscriber.rb b/railties/lib/rails/subscriber.rb
index 2674bf003e..9965786d86 100644
--- a/railties/lib/rails/subscriber.rb
+++ b/railties/lib/rails/subscriber.rb
@@ -63,7 +63,11 @@ module Rails
subscriber = subscribers[namespace.to_sym]
if subscriber.respond_to?(name) && subscriber.logger
- subscriber.send(name, ActiveSupport::Notifications::Event.new(*args))
+ begin
+ subscriber.send(name, ActiveSupport::Notifications::Event.new(*args))
+ rescue Exception => e
+ Rails.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}"
+ end
end
if args[0] == "action_dispatch.after_dispatch" && !subscribers.empty?
diff --git a/railties/lib/rails/tasks/middleware.rake b/railties/lib/rails/tasks/middleware.rake
index e1ab309157..5a5bd7a7e9 100644
--- a/railties/lib/rails/tasks/middleware.rake
+++ b/railties/lib/rails/tasks/middleware.rake
@@ -3,5 +3,5 @@ task :middleware => :environment do
Rails.configuration.middleware.active.each do |middleware|
puts "use #{middleware.inspect}"
end
- puts "run ActionController::Routing::Routes"
+ puts "run #{Rails.application.class.name}"
end