Jason Vogel
2006-Dec-05 14:53 UTC
In a Model, what is the "best practice" for requiring a value
I''m in a find routine, and I don''t want to perform the search if one of the arguments is nil. What is the recommendation from the group? I started to use "assert_not_nil" but that is not defined in my Model chain. Thanks, Jason --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maxim Kulkin
2006-Dec-05 15:06 UTC
Re: In a Model, what is the "best practice" for requiring a value
On 5 December 2006 17:53, Jason Vogel wrote:> I''m in a find routine, and I don''t want to perform the search if one of > the arguments is nil. What is the recommendation from the group? > > I started to use "assert_not_nil" but that is not defined in my Model > chain.return [] unless myvalue =) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Stewart
2006-Dec-05 15:09 UTC
Re: In a Model, what is the "best practice" for requiring a value
On 5 Dec 2006, at 14:53, Jason Vogel wrote:> I''m in a find routine, and I don''t want to perform the search if > one of > the arguments is nil. What is the recommendation from the group? > > I started to use "assert_not_nil" but that is not defined in my Model > chain.How about: return unless arguments.all? ''arguments.all?'' will return true if and only if none of the collection members is false or nil. If an argument can be false, you could do this: return unless arguments.all? { |arg| !arg.nil? } Regards, Andy Stewart --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Francois Beausoleil
2006-Dec-05 15:11 UTC
Re: In a Model, what is the "best practice" for requiring a value
Hello Jason, 2006/12/5, Jason Vogel <jasonvogel@gmail.com>:> I'm in a find routine, and I don't want to perform the search if one of > the arguments is nil. What is the recommendation from the group?raise ArgumentError, "Parameter X is required" if x.blank? Hope that helps ! -- François Beausoleil http://blog.teksol.info/ http://piston.rubyforge.org/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Vogel
2006-Dec-05 15:15 UTC
Re: In a Model, what is the "best practice" for requiring a value
Thanks guys, you hit both questions (fail loudly and fail silently)... On Dec 5, 9:11 am, "Francois Beausoleil" <francois.beausol...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Jason, > > 2006/12/5, Jason Vogel <jasonvo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > I''m in a find routine, and I don''t want to perform the search if one of > > the arguments is nil. What is the recommendation from the group?raise ArgumentError, "Parameter X is required" if x.blank? > > Hope that helps ! > -- > François Beausoleilhttp://blog.teksol.info/http://piston.rubyforge.org/--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---