Thursday, June 24, 2010

Re: [Rails] DRY a named scope

On Jun 24, 2010, at 3:34 PM, Me wrote:

> Is there a way to DRY this up a bit?
>
> named_scope :has_valid_sysoid, lambda{|sysoid|
> (sysoid.nil?) ? {:conditions => ["nodesysoid IS NOT NULL AND
> nodelabel LIKE '%-to-%'"], :include => [:ipinterface, :alarm]} :
> {:conditions => ["nodesysoid IS NOT NULL AND nodelabel LIKE '%-to-%'
> AND nodesysoid = ? ", sysoid], :include => [:ipinterface, :alarm]}
> }

You could move the condition inside the {}'s so it only affects the value of the :conditions key.

But... I would be more included to separate the scopes into :has_valid_sysoid and :has_specific_sysoid.

Model.has_valid_sysoid('foo') doesn't really seem to be doing what the scope suggests it's doing... to me anyway.. I see a difference b/n "valid" and "a specific".

I don't know if that makes sense for your application or not...

-philip

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate