Skip to content

Commit de6ad56

Browse files
committed
enables the evented monitor in new applications
1 parent b5eb242 commit de6ad56

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

railties/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* New applications are generated with the evented file system monitor enabled
2+
on Linux and Mac OS X.
3+
4+
*Xavier Noria*
5+
16
* Add dummy files for apple-touch-icon.png and apple-touch-icon.png. GH#23427
27

38
*Alexey Zabelin*

railties/lib/rails/generators/app_base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ def spring_install?
390390
!options[:skip_spring] && !options.dev? && Process.respond_to?(:fork) && !RUBY_PLATFORM.include?("cygwin")
391391
end
392392

393+
def os_supports_listen_out_of_the_box?
394+
RbConfig::CONFIG['host_os'] =~ /darwin|linux/
395+
end
396+
393397
def run_bundle
394398
bundle_command('install') if bundle_install?
395399
end

railties/lib/rails/generators/rails/app/templates/Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ group :development do
3838
gem 'web-console', '~> 3.0'
3939
<%- end -%>
4040
<%- end -%>
41+
<% if os_supports_listen_out_of_the_box? -%>
42+
gem 'listen', '~> 3.0.5'
43+
<% end -%>
4144
<% if spring_install? -%>
4245
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
4346
gem 'spring'

railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ Rails.application.configure do
5858

5959
# Use an evented file watcher to asynchronously detect changes in source code,
6060
# routes, locales, etc. This feature depends on the listen gem.
61-
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
61+
<%= '# ' unless os_supports_listen_out_of_the_box? %>config.file_watcher = ActiveSupport::EventedFileUpdateChecker
6262
end

railties/test/generators/app_generator_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,28 @@ def test_inclusion_of_a_debugger
479479
end
480480
end
481481

482+
def test_inclusion_of_listen_related_gems
483+
run_generator
484+
if RbConfig::CONFIG['host_os'] =~ /darwin|linux/
485+
assert_gem 'listen'
486+
else
487+
assert_file 'Gemfile' do |content|
488+
assert_no_match(/listen/, content)
489+
end
490+
end
491+
end
492+
493+
def test_evented_file_update_checker_config
494+
run_generator
495+
assert_file 'config/environments/development.rb' do |content|
496+
if RbConfig::CONFIG['host_os'] =~ /darwin|linux/
497+
assert_match(/^\s*config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
498+
else
499+
assert_match(/^\s*# config.file_watcher = ActiveSupport::EventedFileUpdateChecker/, content)
500+
end
501+
end
502+
end
503+
482504
def test_template_from_dir_pwd
483505
FileUtils.cd(Rails.root)
484506
assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]))

0 commit comments

Comments
 (0)