提交 64ea3dfd 编写于 作者: J José Valim 提交者: Carl Lerche

Add reloadable specific for engines and move environment to application paths.

Signed-off-by: NCarl Lerche <carllerche@mac.com>
上级 d3d48747
...@@ -8,14 +8,16 @@ class Configuration < ::Rails::Engine::Configuration ...@@ -8,14 +8,16 @@ class Configuration < ::Rails::Engine::Configuration
attr_accessor :cache_classes, :cache_store, :colorize_logging, attr_accessor :cache_classes, :cache_store, :colorize_logging,
:consider_all_requests_local, :dependency_loading, :consider_all_requests_local, :dependency_loading,
:filter_parameters, :log_level, :logger, :metals, :filter_parameters, :log_level, :logger, :metals,
:plugins, :preload_frameworks, :reload_plugins, :plugins, :preload_frameworks, :reload_engines, :reload_plugins,
:serve_static_assets, :time_zone, :whiny_nils :serve_static_assets, :time_zone, :whiny_nils
def initialize(*) def initialize(*)
super super
@colorize_logging = true
@filter_parameters = [] @filter_parameters = []
@dependency_loading = true @dependency_loading = true
@serve_static_assets = true @serve_static_assets = true
@time_zone = "UTC"
end end
def paths def paths
...@@ -23,6 +25,7 @@ def paths ...@@ -23,6 +25,7 @@ def paths
paths = super paths = super
paths.app.controllers << builtin_controller if builtin_controller paths.app.controllers << builtin_controller if builtin_controller
paths.config.database "config/database.yml" paths.config.database "config/database.yml"
paths.config.environment "config/environments", :glob => "#{Rails.env}.rb"
paths.log "log/#{Rails.env}.log" paths.log "log/#{Rails.env}.log"
paths.tmp "tmp" paths.tmp "tmp"
paths.tmp.cache "tmp/cache" paths.tmp.cache "tmp/cache"
...@@ -76,10 +79,6 @@ def builtin_controller ...@@ -76,10 +79,6 @@ def builtin_controller
def log_level def log_level
@log_level ||= Rails.env.production? ? :info : :debug @log_level ||= Rails.env.production? ? :info : :debug
end end
def time_zone
@time_zone ||= "UTC"
end
end end
end end
end end
\ No newline at end of file
...@@ -124,7 +124,7 @@ def load_tasks ...@@ -124,7 +124,7 @@ def load_tasks
protected protected
def reloadable?(app) def reloadable?(app)
app.config.reload_plugins app.config.reload_engines
end end
end end
end end
\ No newline at end of file
...@@ -22,7 +22,6 @@ def paths ...@@ -22,7 +22,6 @@ def paths
paths.lib "lib", :load_path => true paths.lib "lib", :load_path => true
paths.lib.tasks "lib/tasks", :glob => "**/*.rake" paths.lib.tasks "lib/tasks", :glob => "**/*.rake"
paths.config "config" paths.config "config"
paths.config.environment "config/environments", :glob => "#{Rails.env}.rb"
paths.config.initializers "config/initializers", :glob => "**/*.rb" paths.config.initializers "config/initializers", :glob => "**/*.rb"
paths.config.locales "config/locales", :glob => "*.{rb,yml}" paths.config.locales "config/locales", :glob => "*.{rb,yml}"
paths.config.routes "config/routes.rb" paths.config.routes "config/routes.rb"
......
...@@ -54,5 +54,11 @@ def config ...@@ -54,5 +54,11 @@ def config
raise "\"#{name}\" is a Railtie/Engine and cannot be installed as plugin" raise "\"#{name}\" is a Railtie/Engine and cannot be installed as plugin"
end end
end end
protected
def reloadable?(app)
app.config.reload_plugins
end
end end
end end
...@@ -18,13 +18,13 @@ class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end ...@@ -18,13 +18,13 @@ class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end
assert_equal "hello", Foo.config.foo.greetings assert_equal "hello", Foo.config.foo.greetings
end end
test "plugin configurations are available in the application" do test "railtie configurations are available in the application" do
class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end
require "#{app_path}/config/application" require "#{app_path}/config/application"
assert_equal "hello", AppTemplate::Application.config.foo.greetings assert_equal "hello", AppTemplate::Application.config.foo.greetings
end end
test "plugin config merges are deep" do test "railtie config merges are deep" do
class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end
class Bar < Rails::Railtie class Bar < Rails::Railtie
config.foo.bar = "bar" config.foo.bar = "bar"
...@@ -33,7 +33,7 @@ class Bar < Rails::Railtie ...@@ -33,7 +33,7 @@ class Bar < Rails::Railtie
assert_equal "bar", Bar.config.foo.bar assert_equal "bar", Bar.config.foo.bar
end end
test "plugin can add subscribers" do test "railtie can add subscribers" do
begin begin
class Foo < Rails::Railtie; subscriber(Rails::Subscriber.new); end class Foo < Rails::Railtie; subscriber(Rails::Subscriber.new); end
assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo] assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo]
......
...@@ -19,5 +19,9 @@ class Engine < ::Rails::Engine ...@@ -19,5 +19,9 @@ class Engine < ::Rails::Engine
plugin.write "lib/another.rb", "class Another; end" plugin.write "lib/another.rb", "class Another; end"
end end
end end
def reload_config
:reload_engines
end
end end
end end
...@@ -15,6 +15,10 @@ def setup ...@@ -15,6 +15,10 @@ def setup
end end
end end
def reload_config
:reload_plugins
end
test "plugin can load the file with the same name in lib" do test "plugin can load the file with the same name in lib" do
boot_rails boot_rails
require "bukkits" require "bukkits"
......
...@@ -31,7 +31,7 @@ def test_plugins_constants_are_not_reloaded_by_default ...@@ -31,7 +31,7 @@ def test_plugins_constants_are_not_reloaded_by_default
def test_plugin_constants_get_reloaded_if_config_reload_plugins def test_plugin_constants_get_reloaded_if_config_reload_plugins
add_to_config <<-RUBY add_to_config <<-RUBY
config.reload_plugins = true config.#{reload_config} = true
RUBY RUBY
boot_rails boot_rails
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册