Skip to content
This repository has been archived by the owner on Dec 25, 2020. It is now read-only.

Reload changed sources #1

Open
nightscape opened this issue Jun 9, 2009 · 1 comment
Open

Reload changed sources #1

nightscape opened this issue Jun 9, 2009 · 1 comment

Comments

@nightscape
Copy link

Hi Michael,

I'm trying to develop an application for which Wee seems very well suited.
One thing that slows down development quite a lot is that when I change the Ruby code of a component, the component does not get reloaded.
Rails and Ramaze both do this and its very useful!
To achieve this, you can reuse Ramaze's source reloader which is a Rack app:
require 'rack/handler/webrick'
require 'ramaze'

app = Rack::Builder.app do
  use Ramaze::Reloader
  Wee::JQuery.install('/jquery', self)
  map '/' do
    run Wee::Application.new {
      Wee::Session.new(HelloWorld.new)
    }
  end
end
Rack::Handler::WEBrick.run(app, :Port => 2000)

This correctly reloads the changed files.
The only problem is that the server is not shut down before the reload and blocking the port.
You can redefine some methods in Ramaze::Reloader::Hooks in order to do this,
but I'm not proficient enough in Rack, WEBrick and Wee to do this.
Anyway, here is what I tried:
$server = nil
Rack::Handler::WEBrick.run(app, :Port => 2000) {|srvr| $server = srvr }
Ramaze::Reloader::Hooks.class_eval do
def before_cycle
$server.shutdown
end
end

It would be great if you could add the missing puzzle peaces.

Thanks a lot!
Martin

@nightscape
Copy link
Author

Ok, my fault... Of course you have to overwrite the method on the Reloader itself,
as the module has already been included before...

$server = nil
Rack::Handler::WEBrick.run(app, :Port => 2000) {|srvr| $server = srvr }
Ramaze::Reloader.class_eval do 
  def before_cycle
    $server.shutdown
  end
end

Now, the files are reloaded correctly and the server shows the changes.
The exception about the already used port is still raised, but that doesn't seem to influence the process.
Maybe you find a nicer solution without exception...

I hope to be able to contribute some nice Ajax components soon :)

Martin

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant