Ruby File Auto-Reloader code

Ruby File Auto-Reloader code

Postby Jim » Sat Oct 02, 2010 7:17 pm

I got tired of reloading files I was editing, so made this up real quick. It uses a timer to check the last modification time on a file, and loads if updated. It handles errors gracefully by only trying to reload a file once per update. If packaged up with a nice user interface, it might make a nice dev tool.

Stop the timer in the Ruby Console: UI.stop_timer $t

Note - It's only good for one file at a time and needs improved if loading multiple files is needed. I just wanted something for "right now," and will try to make it better later.

Code: Select all
def autoreload(name)
    pf = Sketchup.find_support_file('plugins')
    file = File.join(pf, name)
    $t = UI.start_timer(2, true) do
        mt = Kernel.test(?M, file)
        if mt.to_i > $mt.to_i
            puts "Loading: #{File.basename(file)}"
            begin
                load file
            rescue Exception => e
                puts e.message
                puts e.backtrace
            end
            $mt = mt
        end
    end
end

0
Hi

Jim 
Global Moderator
 

Re: Ruby File Auto-Reloader code

Postby Morgan74 » Tue Oct 05, 2010 4:45 pm

Thank-you for this great Plugin !!! :thumb:
It's so boring to always close and re-open SU to update my plugins files !! :twisted:
0

Morgan74 
 

Re: Ruby File Auto-Reloader code

Postby Jim » Wed Oct 06, 2010 3:32 pm

I'm glad you found it useful.

But there are times when it is good to close SketchUp; when you change the name of a method, for example. Closing SketchUp is the only way to get rid of the old method name. Sometimes you have a bug where a part of your code is still using the old method name until you remember you changed it. I've done this numerous times.
0
Hi

Jim 
Global Moderator
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

cron

Who is online

Users browsing this forum: No registered users and 12 guests

Visit our sponsors: