Sha256: 62ff2f2694a61f5f61d1fb94feec01f2b4f6353ac1aec92c95d3450e79dab16d
Contents?: true
Size: 1.9 KB
Versions: 3
Compression:
Stored size: 1.9 KB
Contents
<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>register (Mongrel::URIClassifier)</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" /> </head> <body class="standalone-code"> <pre>/** * call-seq: * uc.register("/someuri", SampleHandler.new) -> nil * * Registers the SampleHandler (one for all requests) with the "/someuri". * When URIClassifier::resolve is called with "/someuri" it'll return * SampleHandler immediately. When called with "/someuri/iwant" it'll also * return SomeHandler immediatly, with no additional searches, but it will * return path info with "/iwant". * * You actually can reuse this class to register nearly anything and * quickly resolve it. This could be used for caching, fast mapping, etc. * The downside is it uses much more memory than a Hash, but it can be * a lot faster. It's main advantage is that it works on prefixes, which * is damn hard to get right with a Hash. */ VALUE URIClassifier_register(VALUE self, VALUE uri, VALUE handler) { int rc = 0; void *ptr = NULL; struct tst *tst = NULL; DATA_GET(self, struct tst, tst); rc = tst_insert((unsigned char *)StringValueCStr(uri), (void *)handler , tst, 0, &ptr); if(rc == TST_DUPLICATE_KEY) { rb_raise(rb_eStandardError, "Handler already registered with that name"); } else if(rc == TST_ERROR) { rb_raise(rb_eStandardError, "Memory error registering handler"); } else if(rc == TST_NULL_KEY) { rb_raise(rb_eStandardError, "URI was empty"); } rb_hash_aset(rb_ivar_get(self, id_handler_map), uri, handler); return Qnil; }</pre> </body> </html>
Version data entries
3 entries across 3 versions & 1 rubygems