Permalink
Browse files

Solve some pendencies.

  • Loading branch information...
1 parent d3c4024 commit 2fde9d774b322fc708990675671231c64c691a33 @josevalim josevalim committed Jan 24, 2010
View
2 actionpack/lib/action_dispatch/railtie.rb
@@ -6,7 +6,7 @@ class Railtie < Rails::Railtie
plugin_name :action_dispatch
# Initialize route files to an array
- config.action_dispatch.route_files = []
+ config.action_dispatch.route_paths = []
# Prepare dispatcher callbacks and run 'prepare' callbacks
initializer "action_dispatch.prepare_dispatcher" do |app|
View
5 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 @@ class Application < Engine
# 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 @@ def instance
end
def inherited(base)
+ raise "You cannot have more than one Rails::Application" if Rails.application
super
Rails.application = base.instance
base.require_environment!
View
2 railties/lib/rails/application/finisher.rb
@@ -17,7 +17,7 @@ module Finisher
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
View
2 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
View
13 railties/lib/rails/application/routes_reloader.rb
@@ -1,17 +1,16 @@
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
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 @@ def reload!
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 @@ def reload_if_changed
end
end
- def files
- @config.action_dispatch.route_files
+ def paths
+ @config.action_dispatch.route_paths
end
end
end
View
4 railties/lib/rails/engine.rb
@@ -67,9 +67,9 @@ def load_tasks
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
View
23 railties/lib/rails/paths.rb
@@ -31,22 +31,21 @@ def initialize(path)
@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 @@ def push(*)
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
View
9 railties/lib/rails/plugin.rb
@@ -6,8 +6,6 @@ def self.inherited(base)
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 @@ def config
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
View
1 railties/test/paths_test.rb
@@ -3,6 +3,7 @@
class PathsTest < ActiveSupport::TestCase
def setup
+ File.stubs(:exists?).returns(true)
@root = Rails::Paths::Root.new("/foo/bar")
end
View
6 railties/test/plugins/configuration_test.rb
@@ -26,11 +26,11 @@ class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end
test "plugin config merges are deep" do
class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end
- class MyApp < Rails::Application
+ class Bar < Rails::Railtie
config.foo.bar = "bar"
end
- assert_equal "hello", MyApp.config.foo.greetings
- assert_equal "bar", MyApp.config.foo.bar
+ assert_equal "hello", Bar.config.foo.greetings
+ assert_equal "bar", Bar.config.foo.bar
end
test "plugin can add subscribers" do

0 comments on commit 2fde9d7

Please sign in to comment.