class ActiveReloader::FileSystem
Public Class Methods
new(request)
click to toggle source
# File lib/active_reloader/file_system.rb, line 6 def initialize(request) @request = request end
Public Instance Methods
notify()
click to toggle source
# File lib/active_reloader/file_system.rb, line 10 def notify _notify end
Private Instance Methods
_notify()
click to toggle source
# File lib/active_reloader/file_system.rb, line 16 def _notify response = {"status" => 0} watched_directories = [] rails_root = @request.params["rails_root"] paths = @request.params["paths"] paths.split(",").each do |path| watched_directories << "#{rails_root}/#{path}" end file_paths = [] change_found = false # Time.now.to_i gives us time in UTC start_time = Time.now.to_i end_time = start_time + 25 Find.find(*watched_directories) do |path| if (FileTest.file?(path) && File.basename(path)[0] != ".") # File.mtime gives us time in local time zone. We will convert it to UTC using to_i method on Time file_mtime = Time.parse(File.mtime(path).to_s).to_i if (file_mtime > start_time) change_found = true break end file_paths << path end end while(Time.now.to_i < end_time && change_found == false) file_paths.each do |path| file_mtime = Time.parse(File.mtime(path).to_s).to_i if (file_mtime > start_time) change_found = true break end end end if (change_found) response["status"] = 1 end [response.to_json] end