Ticket #466 (closed enhancement: fixed)

Opened 11 months ago

Last modified 10 months ago

Magic loading of Models and Controllers

Reported by: coryodani..@gmail.com Assigned to: iv..@gweezlebur.com
Priority: major Milestone: 0.5.3
Component: Merb Keywords:
Cc:

Description

Just a patch that will allow models and controllers to be loaded that may inherit from other classes that fall later in the alphabet without having to put a specific require 'whatnot in the class.

Attachments

magic_class_loading_woot.diff (1.5 kB) - added by coryodani..@gmail.com on 01/17/08 16:01:15.
magic_load_path.diff (1.3 kB) - added by coryodani..@gmail.com on 01/17/08 18:05:07.
Forget the other file attached. Use this, plz kthxbye
last_time_i_swear.diff (1.3 kB) - added by coryodani..@gmail.com on 01/17/08 18:12:26.
Ok, thats it i promise, scouts honor.
just_so_that_wasnt_the_last_one.diff (1.9 kB) - added by has.s..@gmail.com on 01/18/08 02:59:40.
omg_4_real_last_patch.diff (2.0 kB) - added by coryodani..@gmail.com on 01/18/08 12:12:42.
omg_4_real_last_patch.2.diff (2.8 kB) - added by coryodani..@gmail.com on 01/18/08 12:31:37.
Liked Hassox's method of using a function, merged my last patch and Hassox's

Change History

01/17/08 16:01:15 changed by coryodani..@gmail.com

  • attachment magic_class_loading_woot.diff added.

01/17/08 18:05:07 changed by coryodani..@gmail.com

  • attachment magic_load_path.diff added.

Forget the other file attached. Use this, plz kthxbye

01/17/08 18:12:26 changed by coryodani..@gmail.com

  • attachment last_time_i_swear.diff added.

Ok, thats it i promise, scouts honor.

01/17/08 18:15:03 changed by iv..@gweezlebur.com

  • owner set to iv..@gweezlebur.com.
  • status changed from new to assigned.

(follow-up: ↓ 8 ) 01/18/08 02:59:15 changed by has.s..@gmail.com

I like this patch a lot.

At the moment though it's limited to a single pass, so depending on order it may not work. This addition to the patch adds a recursive attempt to load the files.

However, if there is a circular dependency it may go into an infinite loop.

What do you think coryodaniel and ivey?

01/18/08 02:59:40 changed by has.s..@gmail.com

  • attachment just_so_that_wasnt_the_last_one.diff added.

01/18/08 08:09:55 changed by coryodani..@gmail.com

I think it only needs the second pass . . . I was trying to think of a circumstance where there would be an issue with circular reference and thats why I have it unshifting onto the array.

ClassA < ClassB (NameError?) => orphans[ClassA]
ClassB < ClassC (NameError?) => orphans[ClassB,ClassA]
ClassC (OK)



On the pass through the orphans:
ClassB < ClassC (OK)
ClassA < ClassB (OK)

01/18/08 10:37:39 changed by coryodani..@gmail.com

We did find a case where there is an issue, I think I have a fix, doing some proofs then I'll upload a new patch.

ClassA < ClassE
ClassB < ClassC
ClassC < ClassA < ClassE

01/18/08 12:12:05 changed by coryodani..@gmail.com

Tested with grandparent inheritance and some alphabetically cyclical inheritance:
ClassA < ClassE
ClassB < ClassC
ClassC < ClassA
ClassD
ClassE
ClassF < ClassA

01/18/08 12:12:42 changed by coryodani..@gmail.com

  • attachment omg_4_real_last_patch.diff added.

01/18/08 12:31:37 changed by coryodani..@gmail.com

  • attachment omg_4_real_last_patch.2.diff added.

Liked Hassox's method of using a function, merged my last patch and Hassox's

01/18/08 12:34:41 changed by coryodani..@gmail.com

I liked hassox's method of using the function, I do think that a random should be avoided as far as the sort. Since a NameError? would only occur in one of two cases 1) It doesn't exist 2) The file name falls later in the alphabet

It still handles all cases as noted in comment#9
WOOHOO MAGIC LOADING!!!

01/18/08 12:35:21 changed by coryodani..@gmail.com

I meant comment # 5, I can't count.

(in reply to: ↑ 2 ) 01/18/08 12:36:05 changed by ojakubi..@gmail.com

I think breaking it out into a separate function is clean, but the random sort on the recursive call is suspect to me. I think the countdown method on the while loop is a safer bet (coryodaniel). Combining these two approaches is a good idea (ie. separate function with a failure countdown).

Replying to has.s..@gmail.com:

I like this patch a lot. At the moment though it's limited to a single pass, so depending on order it may not work. This addition to the patch adds a recursive attempt to load the files. However, if there is a circular dependency it may go into an infinite loop. What do you think coryodaniel and ivey?

01/28/08 14:38:54 changed by iv..@gweezlebur.com

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [1332]) better (non-magic) model/controller loading for dependencies -- closes #466 -- Thanks to all who worked on this one: coryodaniel, oliver, hassox

01/28/08 15:50:34 changed by coryodani..@gmail.com

On yeah, not magic :) I forgot, no magic . . .