[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

auto-reload changed dependancies

Kevin Watt

10/17/2004 3:47:00 PM

Hi Rubyers

Does ruby keep a list of require'd files anywhere? I'd like to make a
method that will loop over them, check the last modification time to see
if they've, and reload them if they have.

One of the frustrating things about rails is that running it as a CGI to
have it auto-reload your changes can take 5-11 seconds to render a page
(at least on windows) - which makes testing a pain. I'm hoping to make
the ruby equilavant of Apache::StatINC in perl, but aren't sure of where
to begin, or if this has already been done before.

Thanks,
Kevin
Allpoetry.com Community Manager



1 Answer

Michael Neumann

10/17/2004 6:05:00 PM

0

On Mon, Oct 18, 2004 at 12:47:24AM +0900, Kevin Watt wrote:
> Hi Rubyers
>
> Does ruby keep a list of require'd files anywhere? I'd like to make a
> method that will loop over them, check the last modification time to see
> if they've, and reload them if they have.

I did that (or something very similar) yesterday for my webframework,
where a auto reload feature can be quite useful.

$LOADED_FEATURES and $LOAD_PATH is your friend.

# autoload.rb
START_TIME = Time.now
Thread.new {
file_mtime = {}
loop do
sleep 1
$LOADED_FEATURES.each do |feature|
$LOAD_PATH.each do |lp|
file = File.join(lp, feature)
if File.exists?(file) and File.stat(file).mtime > (file_mtime[file] || $START_TIME)
file_mtime[file] = File.stat(file).mtime
p "reload #{ file }"
load(file)
end
end
end
end
}

Regards,

Michael