On Saturday, June 16, 2012 2:06:43 PM UTC-7, cult hero wrote:
>
> ActiveRecord can will raise an exception when a record isn't found on 
> .find() and ! methods. This is nice because the railtie will rescue that as 
> :not_found and give you a 404. Doing this manually is also trivial as you 
> can do something like raise NotFound unless @model = Model[params[:id]], 
> but I actually do like the option of raising any exception with a method 
> call. With that said (and way too much back story):
>
> I'd basically like to add a method, probably .find!(), that does just 
> that. It's [] + raising an exception. This seems trivial enough to do, but 
> what I'm stuck on what to do with the exception.
>
> Should I just use something like Sequel::Plugins::<plugin_name>::NotFound 
> or is it possible to have a plugin add a class to an existing namespace. 
> Sequel::Model::NotFound would be ideal. Or, I could even reuse an existing 
> exception, NoExistingObject but this would be using it in a way that's 
> beyond the scope of its documentation. For now I think I'm going to do the 
> latter but I'll make changes based on any feedback I get here.
>

I think it's probably best to create a new plugin and exception class 
(which would subclass Sequel::Error).  NoExistingObject sounds good, but it 
indicates a serious issue when updating or deleting, so I don't think it is 
appropriate to reuse for your purposes.  Your find! method would just go in 
the plugin's ClassMethods, and would raise that error.
 

> (PS: Forme rules. I spent a bunch of time working on a plugin for Sequel 
> so it would work with simple_form when I stumbled onto that.)
>

Thanks!  I'm using Forme in a couple of projects (one Rails, one Sinatra).  
I haven't had a lot of feedback regarding it, so it you have any, please 
let me know.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/bXP9zI7gxvIJ.
To post to this group, send email to sequel-talk@googlegroups.com.
To unsubscribe from this group, send email to 
sequel-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to