On May 4, 4:08 pm, Hiten <[email protected]> wrote:
> Hi,
>
> I have creating a few dataset methods with def_dataset_method and want
> to also have those methods available to the model. Is this possible? I
> have a feeling this may be built-in, but can't figure it out.
>
> e.g.:
>
> Post < Sequel::Model
> def_dataset_method(:hide)
> update(:status => 'unpublished')
> end
> end
>
> So this works:
> Post.filter(:name => 'old').hide
> But I'm also looking for this:
> Post[2342].hide
>
> To get both of these working, do I need to create a separate instance
> method for 'hide'?
You need to create a separate instance method. Your case is one where
the same code will be able to work for both, so you could do:
class Post
prok = proc{update(:status => 'unpublished')}
[:def_dataset_method, :define_method].each{|s| send(s, :hide,
&prok)}
end
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.