Re: Re: getting all controllers for application

Dee Zsombor
Wed, 11 May 2005 08:05:24 -0000

On 5/11/05, Jeremy Kemper <jeremy-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org>
wrote:

> Keeping a constant in environment.rb doesn''t seem bad.  However,
> greater introspection into controllers and actions would be nice for
> an easy-admin scaffolding.

Would that not help Routing also? Expanding all those :controller and
:action items to real names  reduceing them to constant strings ....
Then cache partial url  to regexes for next matcing items  in a hash.

For example
rules
  app/:controller/:action/:id
  yoda/:controller/:action/:id

would expand to:
  app/note/view
  app/note/edit
  app/note/destroy
  app/task/view
  yoda/ynote/yview
  yoda/ynote/yedit
  yoda/ynote/ydestroy
  yoda/ytask/yview

that can be represented with:

next_item_for[[''app'']]  =   /(note)|(task)/
next_item_for[[''yoda'']] =  /(ynote)|(ytask)/
next_item_for[[''app'',note'']] =
/(view)|(edit)|(destroy)/
next_item_for[[''app'',task'']] = /(view)/
next_item_for[[''yoda'',''ynote'']] =
/(yview)|(yedit)|(ydestroy)/
# and so on ....

Format restrictions like  one from
 map.connect ''date/:year/:month/:day'', :controller =>
''blog'', :action
=> ''by_date'',
              :month => nil, :day => nil,
              :requirements => {:year => /\d{4}/, :day => /\d{1,2}/,
:month => /\d{1,2}/}

can be represented like:
next_item_for[[''date'']] = /(\d{4})[\/(\d{1,2)[\/(\d{1,2})]]/
or something similarly scary ;-)

current values for :controller, :action  and other parameters can be
inferred along the way. Perhaps by keeping them in next_item_for
beside regexp matching following items.

Other than being written in C, I can''t find a reason why native
routing should be faster, as by introspecting controller names and
action names we know more about request urls. Besides Ruby regexps and
hashes are also written in C.


--