lib/searchlogic/search.rb
# Responsible for adding a "search" method into your models.
Responsible for adding a "search" method into your models.
Responsible for adding a " search " method into your models .
def method_missing(name, *args, &block)
        condition_name = condition_name(name)
        scope_name = scope_name(condition_name)
        if setter?(name)
          if scope?(scope_name)
            conditions[condition_name] = type_cast(args.first, cast_type(scope_name))
          else
            raise UnknownConditionError.new(condition_name)
          end
        elsif scope?(scope_name)
          if args.size > 0
            send("#{condition_name}=", *args)
            self
          else
            conditions[condition_name]
          end
        else
          scope = conditions.inject(klass.scoped(current_scope) || {}) do |scope, condition|
            scope_name, value = condition
            scope_name = normalize_scope_name(scope_name)
            klass.send(scope_name, value) if !klass.respond_to?(scope_name)
            arity = klass.named_scope_arity(scope_name)
            if !arity || arity == 0
              if value == true
                scope.send(scope_name)
              else
                scope
              end
            else
              scope.send(scope_name, value)
            end
          end
          scope.send(name, *args, &block)
        end
      end
def method_missing ( name , * args , & block ) condition_name = condition_name ( name ) scope_name = scope_name ( condition_name ) if setter? ( name ) if scope? ( scope_name ) conditions [ condition_name ] = type_cast ( args . first , cast_type ( scope_name ) ) else raise UnknownConditionError . new ( condition_name ) end elsif scope? ( scope_name ) if args . size > 0 send ( "#{condition_name}=" , * args ) self else conditions [ condition_name ] end else scope = conditions . inject ( klass . scoped ( current_scope ) || { } ) do | scope , condition | scope_name , value = condition scope_name = normalize_scope_name ( scope_name ) klass . send ( scope_name , value ) if ! klass . respond_to? ( scope_name ) arity = klass . named_scope_arity ( scope_name ) if ! arity || arity == 0 if value == true scope . send ( scope_name ) else scope end else scope . send ( scope_name , value ) end end scope . send ( name , * args , & block ) end end
Responsible for adding a "search" method into your models.
Responsible for adding a " search " method into your models .
name
<not_specific>
args
<not_specific>
block
<not_specific>