DRY a named scope

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

Thanks.

Trying to keep the controller simple: Takes a value or not. One thing I could do was put he include inside the method call but where does the param go?

Node.has_valid_sysoid(..)

The scope is working, just trying cut out the duplication.

named_scope :has_valid_sysoid, lambda{|sysoid|   conditions = ["nodesysoid IS NOT NULL AND nodelabel LIKE '%-to-%']   unless sysoid.nil?     conditions[0]<< " AND nodesysoid = ?"     conditions << sysoid   end   {:conditions => conditions, :include => [:ipinterface, :alarm]} }

<zitiere wer="Me">