On Apr 30, 9:05 am, dusty <[email protected]> wrote:
> Jeremy,
>
> If you use the instance_methods, isn't that going to override any uses
> of hook_class_methods that have been created in a plugin?
>
> For example:
>
> module Sequel
> module Plugins
> class MyPlugin
>
> def self.apply(model, opts={})
> model.plugin :hook_class_methods
> model.before_save do
> self.updated_at = Time.now
> end
> end
>
> end
> end
> end
First, the new way to write this plugin is:
module Sequel
module Plugins
class MyPlugin
class InstanceMethods
def before_save
super
self.updated_at = Time.now
end
end
end
end
end
> For example, when I have this class, and I add a before_save to it,
> the timestamp plugin doesn't run.
>
> class Monkey < Sequel::Model
>
> plugin :my_plugin
>
> def before_save
> self.name += " after"
> end
>
> end
>
> Is there a recommended way around that?
Yes:
class Monkey < Sequel::Model
plugin :my_plugin
def before_save
super
self.name += " after"
end
end
If you have hooks defined by plugins or superclasses, just call
super. It's not a bad idea to always include it, so you don't forget
to when you add a plugin later.
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
-~----------~----~----~----~------~----~------~--~---