Jonathon Anderson wrote:
> The problem with using decorators here is that it doesn't compare to
> things like has_field/with_fields/belongs_to/etc. before_insert is a
> DSL statement at the same level of the other Elixir statements, and
> represents the ability to implement whatever data-defining behavior
> you want as statements.
>
> Callbacks like "before_insert_test" can be decorated, but not field
> definitions, like you see in has_field.
>
> I'm not saying that there shouldn't be decorators in the style of
> @before_insert. Such a syntax would be very simple to implement,
> after all. But to have it be the preferred syntax for defining event
> callbacks would form a mental disconnect between the event hook
> statements and other statements.
Personally, I don't find there to be a disconnect at all. Statements
decorate the class/entity whereas decorators decorate a method. I think
we should go with something like this:
class Person(Entity):
has_field('name', Unicode)
has_field('password', Unicode)
responds_to_events()
@before_insert
@before_update
def validate_password(self):
if len(self.password) < 6:
raise 'Password is too short!'
The `responds_to_events` statement would simply add a mapper extension
that traverses the entity looking for event callbacks, and the
decorators would simply flag which methods are registered for which
callbacks.
If people like this idea (please let me know), I will work this up
tonight or tomorrow evening and get it into SVN for the release.
--
Jonathan LaCour
http://cleverdevil.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---