On Aug 26, 12:55 pm, Scott Tadman <[email protected]> wrote:
> I've made a small plugin to add ActiveRecord-style callbacks to models
> so that porting applications to Sequel is made easier. I'm not sure if
> this is a good idea, bad idea, or if it's a really bad idea, so I'm
> here to ask. As someone who's used ActiveRecord since the early days
> when the new class-method declarations were not available, using
> Sequel which doesn't have them feels like a step back in time.
>
> It's nice that you can just add this on using the plugin system
> instead of having to do some kind of crazy initializer hack.
>
> Sequel::Model with no plugins:
>
>     class MyModel < Sequel::Model
>       def before_validation
>         check_something
>         check_something_else
>       end
>
>       def before_save
>         return unless (some_condition?)
>
>         do_something
>       end
>     end
>
> Sequel::Model with SequelSimpleCallbacks plugin added:
>
>     Sequel::Model.plugin(SequelSimpleCallbacks)
>
>     class MyModel < Sequel::Model
>       before_validation :check_something, :check_something_else
>
>       before_save :do_something, :unless => :some_condition?
>     end

This appears to do the same thing as the built-in hook_class_methods
plugin (http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/
Plugins/HookClassMethods.html).

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" 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/sequel-talk?hl=en.

Reply via email to