Albert S. wrote:
Hi.
I’m learning AcriveRecord (I’m not building web apps for now, just
playing with the database layer).
Problem is, when I run the following code:
require ‘rubygems’
require ‘activerecord’
puts ‘hi’
It takes about 6 seconds. I’m using a slow computer. Now, it’s no fun
playing when it takes so long to ‘require’ all the system.
Can I accelerate things a bit?
I know I can use some Ruby webserver and then the files are saved in
memory compiled, but then what happens if I change my source using my
editor? It won’t be re-loaded by the server.
Any suggestions?
ActiveRecord is a huge library of code. It takes a while. If you are
testing a command line sort of client, I don’t think there is a way
around that. Rails does support code reloading, but that is not default
ruby behaviour.
Something I have done in the past is use the load method. Like in an
IRB prompt, I can execute a bunch of setup, then load and execute.
Change some code, load that file and execute again.
require ‘rubygems’
require ‘activerecord’
load(‘my_file.rb’)
MyFile.do_something!
change my_file.rb code and save
load(‘my_file.rb’)
MyFile.do_something!
You can even shorten that to one line, so you can just go back to IRB,
and hit up arrow, enter.
load(‘my_file.rb’); MyFile.do_something!
This is one way that you can keep active record loaded, and only reload
your changed code.