Question

I want to guard to automatically reload my settingslogic settings when I change a settings file. I guessed putting this in the Guardfile would work, but it didn't. Any ideas?

guard 'settings' do
  watch(%r{^config/.*settings\.yml$}) { "Settings.reload!" }
end
Was it helpful?

Solution

This won't work for several reasons:

  1. There is no Guard plugin guard-settings, so you cannot use guard 'settings'.
  2. The watch block returns a transformed path that the plugin needs to take into account, not a String with Ruby code.
  3. Another problem with this approach is, that your project needs to run in the same process, otherwise reloading the settings will not have an effect on your actual server.

I suggest to make use of Listen in your project (you don't mention if it's Rails, Sinatra, ...) with something like:

Listen.to('config') do |modified, added, removed|
  Settings.reload!
end.start
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top