From rcorsaro at optaros.com Fri Dec 21 11:04:59 2007 From: rcorsaro at optaros.com (Robert C Corsaro) Date: Fri, 21 Dec 2007 11:04:59 -0500 Subject: MouseHole Dead? Message-ID: <476BE42B.1010200@optaros.com> Hi, Trying to get trunk working. Seems a little broken. Can I assume it worked at some point? I'm using mongrel 1.1.2 and most of the problems seem to be because of mongrel. It has probably changed some in the past 8 months. The first problem is lib/mouseHole/app.rb(line 33) : def initialize server, klass_name = nil, model = nil, rb = nil klass_name ||= self.class.name self.model = model self.title = klass_name METADATA.each do |f| self.send("#{f}=", self.class.send("default_#{f}")) end self.klass = klass_name self.path = rb if self.handlers self.handlers.each do |h_is, h_name, h_blk| next unless h_is == :mount server.unregister "/#{h_name}" server.register "/#{h_name}", h_blk end end basic_setup end The unregister method throws an exception if the h_name isn't registered. This is probably just there for safety and mongrel probably didn't throw an exception when it was written. Here is an ugly patch, feel free to make a better one: Index: lib/mouseHole/app.rb =================================================================== --- lib/mouseHole/app.rb (revision 124) +++ lib/mouseHole/app.rb (working copy) @@ -30,7 +30,14 @@ if self.handlers self.handlers.each do |h_is, h_name, h_blk| next unless h_is == :mount - server.unregister "/#{h_name}" + # BOB_HACK: unregister throws an exception if the h_name isn't + # registered, so I catch it + begin + server.unregister "/#{h_name}" + rescue + print "no problem" + end + # END BOB_HACK server.register "/#{h_name}", h_blk end end I've also attached it in case my email is ugly. The second problem is in bin/mouseHole. We are trying to register the uri "http:", but mongrel only allows uris that start with "/". This throws a really ugly nil exception because mongrel is doing some funky stuff. Fist I added this to mogrel-1.1.2/lib/mongrel.rb to figure out what the problem was: rescue URIClassifier::RegistrationError handlers = @classifier.resolve(uri)[2] method_name = in_front ? 'unshift' : 'push' # BOB_HACK: Method assumes exception means something about # handlers already existing and tries to push this one, but it # could be something else this isn't a good solution but it # works for me. if handlers.respond_to?method_name handlers.send(method_name, handler) else raise $! end # END BOB_HACK end I have worked around this by commenting out the check for '/' at the start of the uri(probably a really bad idea) in mongrel-1.1.2/lib/uri_classifier.rb (line 31) : # Register a handler object at a particular URI. The handler can be whatever # you want, including an array. It's up to you what to do with it. # # Registering a handler is not necessarily threadsafe, so be careful if you go # mucking around once the server is running. def register(uri, handler) raise RegistrationError, "#{uri.inspect} is already registered" if @handler_map[uri] raise RegistrationError, "URI is empty" if !uri or uri.empty? # here is my change: #raise RegistrationError, "URI must begin with a \"#{Const::SLASH}\"" unless uri[0..0] == Const::SLASH @handler_map[uri.dup] = handler rebuild end Ok. So now mouseHole starts up. Yippy! My next problem is this: On the app page, there is an enable checkbox, but no submit button. Are all apps automatically enabled? What's up with that? The checkbox does diddly squat. Here is my dump of the mousehole_apps table: BEGIN TRANSACTION; CREATE TABLE mousehole_apps ("id" INTEGER PRIMARY KEY NOT NULL, "script" varchar(255) DEFAULT NULL, "uri" varchar(255) DEFAULT NULL, "active" integer DEFAULT 1 NOT NULL, "matches" text DEFAULT NULL, "created_at" datetime DEFAULT NULL); INSERT INTO "mousehole_apps" VALUES(2,'hoodwinkd.rb','NULL',1,NULL,'2007-12-21 09:48:02'); INSERT INTO "mousehole_apps" VALUES(3,'rcorsaro.rb','NULL',1,NULL,'2007-12-21 09:48:02'); COMMIT; rcorsaro.rb is my test script. It's located in ~/.mouseHole/. Here it is: # Blah Blah mousehole # by Robert Corsaro # Hi There!") end end See anything wrong? I have next week off, so I can work on mouseHole if it needs working on. Does anyone give a shit? -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: unregister.patch Url: http://rubyforge.org/pipermail/mousehole-scripters/attachments/20071221/31659942/attachment.pl