Read more

Telling Spring to watch certain directories/files

Dominik Schöler
June 26, 2014Software engineer at makandra GmbH

If you have some file or directory that should trigger a Spring reboot, tell Spring e.g. in config/spring.rb:

Spring.watch 'file.rb'
Spring.watch 'lib/templates'
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

However, Spring will silently drop paths that do not exist at the time calling #watch. Unless you restart Spring (thereby reloading the watch commands), it won't even watch them once they do exist.

Make sure the watchable paths exist before telling Spring to watch, e.g. with

FileUtils.touch 'file.rb'
FileUtils.mkdir_p 'lib/templates'
Spring.watch 'file.rb'
Spring.watch 'lib/templates'

For the curious, Spring::Watcher::Abstract#add is the culprit.

Posted by Dominik Schöler to makandra dev (2014-06-26 12:50)