Sha256: fd40b5b5fcbb2aa1d6c36c972a254cdb04273d2e19237c13b70c87c0b361e47c
Contents?: true
Size: 1.66 KB
Versions: 2
Compression:
Stored size: 1.66 KB
Contents
require 'facet/dir/self/recurse' module Kernel # A Customized version of the autoreload from Facets. Also # checks template files, and keeps a dirty flag. def autoreload(check_interval=10, glob = '.') Thread.new(Time.now) do |start_time| check_dirty = lambda do |file,hash,file_mtime| if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time) hash[file] = mtime end end file_mtime = {} files = [] Dir.recurse(glob) do |f| if f !~ /\/_darcs\// and f =~ /(.?)\.x(.?)/ files << f end end loop do need_reload = Hash.new sleep check_interval $LOADED_FEATURES.each do |feature| check_dirty.call(feature,need_reload,file_mtime) $LOAD_PATH.each {|lp| check_dirty.call(File.join(lp, feature),need_reload,file_mtime)} end unless need_reload.empty? $autoreload_dirty = true need_reload.each_pair do |file,mtime| file_mtime[file] = mtime Logger.debug "File '#{ file }' reloaded" if $DBG begin load(file) rescue Exception => e Logger.info e.inspect end end end # Check for template files. files.each do |file| if File.exists?(file) and (mtime = File.stat(file).mtime) > (file_mtime[file] || start_time) $autoreload_dirty = true file_mtime[file] = mtime Logger.debug "File '#{ file }' changed" if $DBG end end end # loop end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
glue-0.41.0 | lib/glue/autoreload.rb |
glue-0.40.0 | lib/glue/autoreload.rb |