Permalink
Browse files

Refactored, simplifying any/all scope_options.

Signed-off-by: Ben Johnson <bjohnson@binarylogic.com>
  • Loading branch information...
1 parent 6b8c570 commit b1bd8865f01f8124882a91df3eddee977efbc1e3 laserlemon committed with Aug 19, 2009
Showing with 3 additions and 8 deletions.
  1. +3 −8 lib/searchlogic/named_scopes/conditions.rb
@@ -148,17 +148,12 @@ def scope_options(condition, column_type, sql, value_modifier = nil)
when /_(any|all)$/
searchlogic_lambda(column_type) { |*values|
return {} if values.empty?
- values = values.flatten
+ values.flatten!
- values_to_sub = nil
- if value_modifier.nil?
- values_to_sub = values
- else
- values_to_sub = values.collect { |value| value_with_modifier(value, value_modifier) }
- end
+ values.collect! { |value| value_with_modifier(value, value_modifier) }
join = $1 == "any" ? " OR " : " AND "
- {:conditions => [values.collect { |value| sql }.join(join), *values_to_sub]}
+ {:conditions => [values.collect { |value| sql }.join(join), *values]}
}
else
searchlogic_lambda(column_type) { |value| {:conditions => [sql, value_with_modifier(value, value_modifier)]} }

0 comments on commit b1bd886

Please sign in to comment.