Rack::Reloader how to

529 views
Skip to first unread message

ts

unread,
Sep 10, 2008, 10:34:03 AM9/10/08
to Rack Development
hi,

I cant get the reloader to work and i wonder am i missing something? a
search in this groups mentioned that the reloader will reload the file
which had been 'require'

The way that i tried is:

================================================
1) helloworld.rb
%w{rubygems rack thin}.each{|dep| require dep}

class HelloWorld
def call(env)
[200,{"Content-Type" => "text/html"},"Hello world"]
end
end
===============================================

2) hellotest.rb
require 'helloworld'

app = Rack::Builder.new{
use Rack::CommonLogger
use Rack::Reloader
use Rack::ShowExceptions
run HelloWorld.new


}
Rack::Handler::Thin.run app, :Port => 3000
==============================================

and i run it like:
ruby hellotest.rb

but let say i go and change "Hello world" in helloworld.rb to "hello".
make a refresh in browser. But i still cant see the new string. Is
reloader suppose to function this way?

Matt Todd

unread,
Sep 10, 2008, 11:22:45 AM9/10/08
to rack-...@googlegroups.com
Just a shot in the dark, are you on a *nix based system? One reason
the Reloader wouldn't work is if your last modified time info on the
file isn't changed. Try touching the file (touch hellotest.rb) to
update the modified time and see if it will see the change.

Also, it takes a certain amount of time to reload... though I'm not
sure how long. It shouldn't be much more than 0.5 seconds, though that
is technically a random guess. :)

If you're still having problems, I'll take a look through the code to
make sure nothing is missing or broken a bit later.

Matt

ts

unread,
Sep 10, 2008, 11:56:34 AM9/10/08
to Rack Development
Matt,

yea this is on a Mac.

still no luck. vi and touch helloworld.rb file did showed the updated
time but reload on the newly modified string still fail.

appreciate your help
ts

On Sep 10, 11:22 pm, "Matt Todd" <chiol...@gmail.com> wrote:
> Just a shot in the dark, are you on a *nix based system? One reason
> the Reloader wouldn't work is if your last modified time info on the
> file isn't changed. Try touching the file (touch hellotest.rb) to
> update the modified time and see if it will see the change.
>
> Also, it takes a certain amount of time to reload... though I'm not
> sure how long. It shouldn't be much more than 0.5 seconds, though that
> is technically a random guess. :)
>
> If you're still having problems, I'll take a look through the code to
> make sure nothing is missing or broken a bit later.
>
> Matt
>

ts

unread,
Sep 11, 2008, 10:28:30 PM9/11/08
to Rack Development
hmm.. figured out that if i use rackup, the reload will be
successful .. eg

rackup hellotest.ru -s thin -p 8080

if use the builder and handler to thin, reload wont be successful.

Matt Todd

unread,
Sep 12, 2008, 2:19:52 AM9/12/08
to rack-...@googlegroups.com
That's interesting and it sucks.

I've been debugging for about an hour now... and for some reason @last
keeps getting updated to Time.now even though no code around it gets
executed...

Fucking baffled.

Still working on it.

Matt

Matt Todd

unread,
Sep 12, 2008, 2:32:10 AM9/12/08
to rack-...@googlegroups.com
Solved it.

http://gist.github.com/10383

You have to call #to_app on the end of the Rack::Builder block
otherwise the #initialize method for the Rack::Reloader (and other
classes, probably, but didn't check) gets run every single request.

So...

app = Rack::Builder.new do


use Rack::CommonLogger
use Rack::Reloader
use Rack::ShowExceptions
run HelloWorld.new

end.to_app

Is this a bug?

Matt

ts

unread,
Sep 12, 2008, 3:41:15 AM9/12/08
to Rack Development
Matt, thanks for figuring it out. I'm still new to ruby and it will
definitely takes me a long time to know what's happening in the code.

to_app work though .. haha

On Sep 12, 2:32 pm, "Matt Todd" <chiol...@gmail.com> wrote:
> Solved it.
>
> http://gist.github.com/10383
>
> You have to call #to_app on the end of the Rack::Builder block
> otherwise the #initialize method for the Rack::Reloader (and other
> classes, probably, but didn't check) gets run every single request.
>
> So...
>
> app = Rack::Builder.new do
>   use Rack::CommonLogger
>   use Rack::Reloader
>   use Rack::ShowExceptions
>   run HelloWorld.new
> end.to_app
>
> Is this a bug?
>
> Matt
>
> On Fri, Sep 12, 2008 at 2:19 AM, Matt Todd <chiol...@gmail.com> wrote:
> > That's interesting and it sucks.
>
> > I've been debugging for about an hour now... and for some reason @last
> > keeps getting updated to Time.now even though no code around it gets
> > executed...
>
> > Fucking baffled.
>
> > Still working on it.
>
> > Matt
>

Christian Neukirchen

unread,
Sep 12, 2008, 11:43:48 AM9/12/08
to rack-...@googlegroups.com
"Matt Todd" <chio...@gmail.com> writes:

> Solved it.
>
> http://gist.github.com/10383
>
> You have to call #to_app on the end of the Rack::Builder block
> otherwise the #initialize method for the Rack::Reloader (and other
> classes, probably, but didn't check) gets run every single request.
>
> So...
>
> app = Rack::Builder.new do
> use Rack::CommonLogger
> use Rack::Reloader
> use Rack::ShowExceptions
> run HelloWorld.new
> end.to_app
>
> Is this a bug?

No.

But maybe there should be a Rack::Builder.make do..end that runs
to_app automatically.

> Matt

--
Christian Neukirchen <chneuk...@gmail.com> http://chneukirchen.org

Matt Todd

unread,
Sep 12, 2008, 12:32:49 PM9/12/08
to rack-...@googlegroups.com
On Fri, Sep 12, 2008 at 11:43 AM, Christian Neukirchen
<chneuk...@gmail.com> wrote:
>> Is this a bug?
>
> No.
>
> But maybe there should be a Rack::Builder.make do..end that runs
> to_app automatically.

For some reason I had thought that that was the default behavior.

Totally for it.

Matt

Christian Neukirchen

unread,
Sep 12, 2008, 1:56:53 PM9/12/08
to rack-...@googlegroups.com
"Matt Todd" <chio...@gmail.com> writes:

But it can't be called #new then, that would be too magic.

Matt Todd

unread,
Sep 12, 2008, 2:12:19 PM9/12/08
to rack-...@googlegroups.com
What about Rack::Builder.app(&block) as a wrapper for
Rack::Builder.new(&block).to_app?

Matt

Reply all
Reply to author
Forward
0 new messages