lib/searchlogic/named_scopes/conditions.rb
# This method helps cut down on defining scope options for conditions that allow *_any or *_all conditions.
# Kepp in mind that the lambdas get cached in a method, so you want to keep the contents of the lambdas as
# fast as possible, which is why I didn't do the case statement inside of the lambda.
This method helps cut down on defining scope options for conditions that allow *_any or *_all conditions.
Kepp in mind that the lambdas get cached in a method, so you want to keep the contents of the lambdas as
fast as possible, which is why I didn't do the case statement inside of the lambda.
This method helps cut down on defining scope options for conditions that allow * _any or * _all conditions . Kepp in mind that the lambdas get cached in a method so you want to keep the contents of the lambdas as fast as possible which is why I didn ' t do the case statement inside of the lambda .
def scope_options(condition, column_type, sql, value_modifier = nil)
          case condition.to_s
          when /_(any|all)$/
            searchlogic_lambda(column_type) { |*values|
              return {} if values.empty?
              values.flatten!
              values.collect! { |value| value_with_modifier(value, value_modifier) }
              join = $1 == "any" ? " OR " : " AND "
              scope_sql = values.collect { |value| sql.is_a?(Proc) ? sql.call(value) : sql }.join(join)
              {:conditions => [scope_sql, *expand_range_bind_variables(values)]}
            }
          else
            searchlogic_lambda(column_type) { |*values|
              values.collect! { |value| value_with_modifier(value, value_modifier) }
              scope_sql = sql.is_a?(Proc) ? sql.call(*values) : sql
              {:conditions => [scope_sql, *expand_range_bind_variables(values)]}
            }
          end
        end
def scope_options ( condition , column_type , sql , value_modifier = nil ) case condition . to_s when / _(any|all)$ / searchlogic_lambda ( column_type ) { | * values | return { } if values . empty? values . flatten! values . collect! { | value | value_with_modifier ( value , value_modifier ) } join = $1 == "any" ? " OR " : " AND " scope_sql = values . collect { | value | sql . is_a? ( Proc ) ? sql . call ( value ) : sql } . join ( join ) { :conditions => [ scope_sql , * expand_range_bind_variables ( values ) ] } } else searchlogic_lambda ( column_type ) { | * values | values . collect! { | value | value_with_modifier ( value , value_modifier ) } scope_sql = sql . is_a? ( Proc ) ? sql . call ( * values ) : sql { :conditions => [ scope_sql , * expand_range_bind_variables ( values ) ] } } end end
This method helps cut down on defining scope options for conditions that allow *_any or *_all conditions.
This method helps cut down on defining scope options for conditions that allow * _any or * _all conditions .
condition
<not_specific>
column_type
<not_specific>
sql
<not_specific>
value_modifier
<not_specific>