[Nitro] injecting Og functionality

transfire at gmail.com transfire at gmail.com
Wed Mar 14 14:42:05 EDT 2007



On Mar 14, 1:01 pm, "Antoniolo" <antoni... at gmail.com> wrote:
> I think model needs to be refactored as soon as possible.
>
> The current way to insert an Og functionally in a regular object is
> including the module ModelMixin, extending Og::Model or using
> attr_accessor/property, right?
>
> imho, the problems begins there.

Those are so much an issue, they are just instigators of enchanting
the class, though one can argue the later attr/propery case is too
magical.

> The last one, inside ann_attr.rb, there's a callback to customize the
> default attr_accessor behaviour. Basically speaking, it places the Og
> funcionalitty through:
> target.send(:include, Og::ModelMixin) if ....
> target.send(:include, Og::Mixin::Validation)...
>
> In fact, ModelMixin as far as I can guess is nothing more than
> instance_methods/class_methods for Model Class (modularized code).
> Validation is also other piece of code regarding only to Model class. My
> point is: the injecting mechanism is knowing much about model's. You know,
> if we add more and more functionality to models, we'll end up having to
> update the injection mechanism as well as the model by itself.

If I understand you correctly, I agree. It should not be using this
injection mechanism, and I have tried many times to convince George of
this. It should be using regular mixins, whic go into Model. Then one
includes (or subclasses) Model and that's it. There are some edge
cases where it is difficult not to inject code, but those should be
the exception to the rule.

> I can leisurely guess the initial idea of Og is to place the functionality
> in models seamlessly. I mean without any explicit inheritance mechanism. But
> I think it's not too ulgy to use it in application-side:
>
> class Person < Og::Model
> end

I agree, but it could be even nicer:

  class Customer is Persisted
  end

or something like that (the point is the "is"). OTOH, George worked it
out pretty well that a class is only going to be picked up by Og if
you use the :class annotation on an attribute. Eg.

  attr :name, String

But maybe one would want to use those annotations and still not have
Og enchant it?

> After all, we can rename ModelMixin to its real purpose (InstanceMethods,
> ClassMethods).

Isn't necessary, just use class_extension block.

T.



More information about the Nitro-general mailing list