Created
June 26, 2011 18:40
-
-
Save paneq/1047845 to your computer and use it in GitHub Desktop.
My second solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'guard' | |
require 'guard/guard' | |
require 'libnotify' | |
require 'thread' | |
module Guard | |
class Development < Guard | |
Sempahore = Mutex.new | |
def self.last_update | |
Sempahore.synchronize do | |
@last_update ||= Time.now | |
end | |
end | |
def self.update | |
Sempahore.synchronize do | |
@last_update = Time.now | |
end | |
end | |
# Called on file(s) modifications | |
def run_on_change(paths) | |
self.class.update | |
end | |
def self.try | |
Thread::new do # http://www.ruby-doc.org/core/classes/Thread.html | |
::Guard.setup | |
::Guard.start(:guardfile_contents => " | |
guard 'development' do | |
watch(%r{^app/(.+)\.rb}) | |
end | |
") | |
end | |
end | |
end | |
end | |
Guard::Development.try if Rails.env.development? && defined?(Rails::Server) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
initializer :set_clear_dependencies_hook do | |
unless config.cache_classes | |
changed_at = Proc.new{ Guard::Development.last_update } | |
last_change = changed_at.call | |
ActionDispatch::Callbacks.before do | |
change = changed_at.call | |
if change > last_change | |
last_change = change | |
ActiveSupport::Notifications.instrument("server.reloading") do | |
ActiveSupport::DescendantsTracker.clear | |
ActiveSupport::Dependencies.clear | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment