Sha256: 4cfd3e7755708fa753fa870c9218a5b4a4bb74104ee282651a5d7c5ac9e319b6

Contents?: true

Size: 933 Bytes

Versions: 3

Compression:

Stored size: 933 Bytes

Contents

# -*- encoding : utf-8 -*-
require 'search/conditions/abstract'

module RademadeAdmin
  module Search
    module Conditions
      class List < Abstract

        protected

        def where
          where_conditions = RademadeAdmin::Search::Part::Where.new(:and)
          @params.slice(*@data_items.origin_fields).each do |field, value|
            where_conditions.add(field, value)
          end
          where_conditions
        end

        def order
          order_conditions = super
          field = @params[:sort] || default_order_field
          order_conditions.unshift(field, @params[:direction])
          order_conditions
        end

        def page
          @params[:page] || 1
        end

        def per_page
          @params[:paginate] || 20
        end

        private

        def default_order_field
          @data_items.has_field?(:position) ? :position : :id
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rademade_admin-0.1.3 app/services/search/conditions/list.rb
rademade_admin-0.1.2 app/services/search/conditions/list.rb
rademade_admin-0.1.1 app/services/search/conditions/list.rb