Sha256: e4d3aefd324348c371b9ff05d4939441636c5e8137ce286334b179ac898e7608

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

module Ixtlan
  module Controllers
    module SearchQuery

      private 
      def query(model, *parameters)
        _query(model, false, *parameters)
      end

      def query_limit_all(model, *parameters)
        _query(model, true, *parameters)
      end

      def _query(model, limit_all, *parameters)
        result = nil
        value = parameters[0].is_a?(String) ? parameters.shift : params[:query]
        if value
          parameters.each do |p|
            args = {}
            if "false" == params[:fuzzy]
              args[p] = value
            else
              args[p.like] = "%" + value.to_s + "%"
            end
            if result
              result = result + model.all(args)
            else
              result = model.all(args)
            end
          end
        end
        if limit_all || value
          limit = (params[:limit] || 10).to_i + 1
          offset = (params[:offset] || 0).to_i
          
          (result || model.all)[offset, offset + limit]
        else
          model.all
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ixtlan-0.4.3 lib/ixtlan/controllers/search_query.rb
ixtlan-0.4.2 lib/ixtlan/controllers/search_query.rb
ixtlan-0.4.1 lib/ixtlan/controllers/search_query.rb
ixtlan-0.4.0 lib/ixtlan/controllers/search_query.rb