[Nitro] Fwd: Troubles along the class-level heirarchy
TRANS
transfire at gmail.com
Wed Jun 7 22:16:56 EDT 2006
On 6/5/06, Jonas Pfenniger <zimba.tm at gmail.com> wrote:
> If you take Nitro::Scaffold, all class methods are also to be extended
> except self.included(klass) naturally. You often don't want to inherit
> that method. This is the perfect case where you need a ClassMethods
> module.
Looking at this code.... well, lets start here: Is this really
supposed to define the same method three times in a row?
# to_edit_href
# ex: admin/articles/edit/23
define_instance_method klass, :to_admin_href, %{
"\#{AdminController.mount_path}/\#{self.class.name.underscore.pluralize}/edit/\#{oid}"
}
if defined? AdminController
# to_admin_href
# ex: admin/articles/list
define_instance_method klass, :to_admin_href, %{
"\#{AdminController.mount_path}/\#{self.class.name.underscore.pluralize}/list"
}
# to_admin_href
# ex: admin/articles/list
define_class_method klass, :to_admin_href, %{
"\#{AdminController.mount_path}/\#{self.name.underscore.pluralize}/list"
}
> Otherwise, look in "nitro/lib/nitro/controller.rb". There is a mess
> with the Publishable module I don't even want to understand.
Is that module being used at all? Is there something preventing it
from using class_inherit?
I just want to make sure all you Glyceriders... I mean the NCT ;) knows that
def self.included( base )
base.module_eval { ... }
end
is a NO NO. It misrepresents what's really going on. The class
hierachy will show the module included, but in actually the code has
been pasted directly into the class --their is no inheritance, you
couldn't redefine a method and call super from it, etc. Moreover the
class methods one might define in this way, to get around the lack of
class-level module inheritance, are only effective at one level, a
module of this kind included in another module will not be effective.
So please do not use this technique and help root out all occurances
of it. I spent a good bit of time myself getting rid of it in Og about
a year ago.
Unfortuantely Ruby doesn't exactly make the proper approach very easy.
But in most cases using class_inherit (from Facets) will do the trick
--it sets up proper module inheritace through the class level hierachy
(and BTW is the successor to the out-dated ClassMethods approach).
The other alternative is an actual "code paste" component system. An
expiremental one is codepack.rb in Facets' forge/ folder --but I'm not
convinced it's the neccessarily the good approach. It does have some
minor efficency advantages but it too thwarts inheritance and has the
same one-level deep issue.
HTH,
T.
More information about the Nitro-general
mailing list