문제

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
도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top