diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-24 09:00:18 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-24 09:32:54 +0100 |
commit | 2fde9d774b322fc708990675671231c64c691a33 (patch) | |
tree | f38713fcab2e54cf4ad34652042df34864608440 /railties/lib | |
parent | d3c40242a58a8863cd216f6639f93df5fdb0c075 (diff) | |
download | rails-2fde9d774b322fc708990675671231c64c691a33.tar.gz rails-2fde9d774b322fc708990675671231c64c691a33.tar.bz2 rails-2fde9d774b322fc708990675671231c64c691a33.zip |
Solve some pendencies.
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/application.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/application/finisher.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/application/railties.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/application/routes_reloader.rb | 13 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/paths.rb | 23 | ||||
-rw-r--r-- | railties/lib/rails/plugin.rb | 9 |
7 files changed, 33 insertions, 25 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 504a241da8..a8ff125342 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -1,8 +1,7 @@ require 'fileutils' require 'rails/railties_path' -require 'rails/railtie' -require 'rails/engine' require 'rails/plugin' +require 'rails/engine' module Rails class Application < Engine @@ -14,7 +13,6 @@ module Rails # TODO Check helpers works as expected # TODO Check routes namespaces - # TODO raise "You cannot have more than one Rails::Application" if Rails.application # TODO Ensure production settings are read properly class << self private :new @@ -25,6 +23,7 @@ module Rails end def inherited(base) + raise "You cannot have more than one Rails::Application" if Rails.application super Rails.application = base.instance base.require_environment! diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 2ac881ac11..db19011b7f 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -17,7 +17,7 @@ module Rails initializer :add_builtin_route do |app| if Rails.env.development? - app.config.action_dispatch.route_files << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') + app.config.action_dispatch.route_paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb') end end diff --git a/railties/lib/rails/application/railties.rb b/railties/lib/rails/application/railties.rb index d167d9bf4f..b3e6693f89 100644 --- a/railties/lib/rails/application/railties.rb +++ b/railties/lib/rails/application/railties.rb @@ -1,7 +1,7 @@ module Rails class Application class Railties - # TODO Write tests + # TODO Write tests for this behavior extracted from Application def initialize(config) @config = config end diff --git a/railties/lib/rails/application/routes_reloader.rb b/railties/lib/rails/application/routes_reloader.rb index 6d61de2320..d861d27465 100644 --- a/railties/lib/rails/application/routes_reloader.rb +++ b/railties/lib/rails/application/routes_reloader.rb @@ -1,8 +1,7 @@ module Rails class Application class RoutesReloader - # TODO Change config.action_dispatch.route_files to config.action_dispatch.routes_path - # TODO Write tests + # TODO Write tests for this behavior extracted from Application def initialize(config) @config, @last_change_at = config, nil end @@ -10,8 +9,8 @@ module Rails def changed_at routes_changed_at = nil - files.each do |file| - config_changed_at = File.stat(file).mtime + paths.each do |path| + config_changed_at = File.stat(path).mtime if routes_changed_at.nil? || config_changed_at > routes_changed_at routes_changed_at = config_changed_at @@ -26,7 +25,7 @@ module Rails routes.disable_clear_and_finalize = true routes.clear! - files.each { |file| load(file) } + paths.each { |path| load(path) } routes.finalize! nil @@ -42,8 +41,8 @@ module Rails end end - def files - @config.action_dispatch.route_files + def paths + @config.action_dispatch.route_paths end end end diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index d972050dc9..cc878ac8f2 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -67,9 +67,9 @@ module Rails config.load_once_paths.freeze end - initializer :add_routing_files do + initializer :add_routing_paths do config.paths.config.routes.to_a.each do |route| - config.action_dispatch.route_files.unshift(route) if File.exists?(route) + config.action_dispatch.route_paths.unshift(route) if File.exists?(route) end end diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb index 88c0c1c68c..55874813da 100644 --- a/railties/lib/rails/paths.rb +++ b/railties/lib/rails/paths.rb @@ -31,22 +31,21 @@ module Rails @all_paths = [] end - def load_once - all_paths.map { |path| path.paths if path.load_once? }.compact.flatten.uniq + def all_paths + @all_paths.uniq! + @all_paths end - def eager_load - all_paths.map { |path| path.paths if path.eager_load? }.compact.flatten.uniq + def load_once + filter { |path| path.paths if path.load_once? } end - # TODO Discover why do we need to call uniq! here - def all_paths - @all_paths.uniq! - @all_paths + def eager_load + filter { |path| path.paths if path.eager_load? } end def load_paths - all_paths.map { |path| path.paths if path.load_path? }.compact.flatten.uniq + filter { |path| path.paths if path.load_path? } end def push(*) @@ -56,6 +55,12 @@ module Rails alias unshift push alias << push alias concat push + + protected + + def filter(&block) + all_paths.map(&block).compact.flatten.uniq.select { |p| File.exists?(p) } + end end class Path diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 394e634903..62dc7f30f8 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -6,8 +6,6 @@ module Rails raise "You cannot inherit from Rails::Plugin" end - # TODO Right now, if a plugin has an Engine or a Railtie inside it, - # the initializers for this plugin will be executed twice. def self.all(list, paths) plugins = [] paths.each do |path| @@ -39,5 +37,12 @@ module Rails config = app.config eval(File.read(file), binding, file) if file && File.file?(file) end + + # TODO Write tests for this sanity check + initializer :sanity_check_railties_collision do + if Engine.subclasses.map { |k| k.root.to_s }.include?(root.to_s) + raise "The plugin #{name.inspect} is a Railtie or an Engine and cannot be installed as Plugin" + end + end end end |