let config.file_watcher be the way to enable the evented file watcher

Before this commit, the sole presence of the Listen constant
enabled the evented file watcher (unless listen resorted to
the polling backend).

This way, applications may depend on listen for other stuff
independently of this feature. Also, allows teams with mixed
setups to decide at boot time whether the evented watcher
should be enabled for each particular instance.
This commit is contained in:
Xavier Noria 2015-12-13 18:37:24 +01:00
parent 6be27016df
commit 7223596259
6 changed files with 31 additions and 31 deletions

View File

@ -7,13 +7,18 @@
*Michael Grosser*
* Implements an evented file system monitor to asynchronously detect changes
in the application source code, routes, locales, etc.
* Implements an evented file watcher to asynchronously detect changes in the
application source code, routes, locales, etc.
To opt-in load the [listen](https://github.com/guard/listen) gem in `Gemfile`:
This watcher is disabled by default, applications my enable it in the configuration:
# config/environments/development.rb
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
This feature depends on the [listen](https://github.com/guard/listen) gem:
group :development do
gem 'listen', '~> 3.0.4'
gem 'listen', '~> 3.0.5'
end
*Puneet Agarwal* and *Xavier Noria*

View File

@ -98,7 +98,7 @@ application. Accepts a valid week day symbol (e.g. `:monday`).
* `config.exceptions_app` sets the exceptions application invoked by the ShowException middleware when an exception happens. Defaults to `ActionDispatch::PublicExceptions.new(Rails.public_path)`.
* `config.file_watcher` the class used to detect file updates in the filesystem when `config.reload_classes_only_on_change` is true. Must conform to `ActiveSupport::FileUpdateChecker` API.
* `config.file_watcher` is the class used to detect file updates in the file system when `config.reload_classes_only_on_change` is true. Rails ships with `ActiveSupport::FileUpdateChecker`, the default, and `ActiveSupport::EventedFileUpdateChecker` (this one depends on the [listen](https://github.com/guard/listen) gem). Custom classes must conform to the `ActiveSupport::FileUpdateChecker` API.
* `config.filter_parameters` used for filtering out the parameters that
you don't want shown in the logs, such as passwords or credit card

View File

@ -1,3 +1,8 @@
* The generated config file for the development environment includes a new
config line, commented out, showing how to enable the evented file watcher.
*Xavier Noria*
* `config.debug_exception_response_format` configures the format used
in responses when errors occur in development mode.
@ -38,11 +43,6 @@
*Yuki Nishijima*
* Generated `Gemfile`s for new applications include a new dependency on
[listen](https://github.com/guard/listen) commented out.
*Puneet Agarwal* and *Xavier Noria*
* Deprecate `serve_static_files` in favor of `public_file_server.enabled`.
Unifies the static asset options under `public_file_server`.

View File

@ -44,7 +44,7 @@ module Rails
@railties_order = [:all]
@relative_url_root = ENV["RAILS_RELATIVE_URL_ROOT"]
@reload_classes_only_on_change = true
@file_watcher = file_update_checker
@file_watcher = ActiveSupport::FileUpdateChecker
@exceptions_app = nil
@autoflush_log = true
@log_formatter = ActiveSupport::Logger::SimpleFormatter.new
@ -191,26 +191,21 @@ module Rails
SourceAnnotationExtractor::Annotation
end
private
def file_update_checker
ActiveSupport::FileUpdateChecker
class Custom #:nodoc:
def initialize
@configurations = Hash.new
end
class Custom #:nodoc:
def initialize
@configurations = Hash.new
end
def method_missing(method, *args)
if method =~ /=$/
@configurations[$`.to_sym] = args.first
else
@configurations.fetch(method) {
@configurations[method] = ActiveSupport::OrderedOptions.new
}
end
def method_missing(method, *args)
if method =~ /=$/
@configurations[$`.to_sym] = args.first
else
@configurations.fetch(method) {
@configurations[method] = ActiveSupport::OrderedOptions.new
}
end
end
end
end
end
end

View File

@ -48,10 +48,6 @@ group :development do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
<% end -%>
# Loading the listen gem enables an evented file system monitor. Check
# https://github.com/guard/listen#listen-adapters if on Windows or *BSD.
# gem 'listen', '~> 3.0.5'
end
<% end -%>

View File

@ -55,4 +55,8 @@ Rails.application.configure do
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end