Sha256: 9e43bf08c918a7c54b67c65574d1467dfb47607d4a39e21adad1faf252c6eae5

Contents?: true

Size: 1.04 KB

Versions: 13

Compression:

Stored size: 1.04 KB

Contents

require_relative 'pagination_handler'

module Praxis
  module Extensions
    module Pagination
      class SequelPaginationHandler < PaginationHandler

        def self.where_lt(query, attr, value)
          query.where("#{attr} < ?", value)
        end
        
        def self.where_gt(query, attr, value)
          query.where("#{attr} > ?", value)
        end

        def self.order(query, order)
          return query unless order
          order_clause = order.map do |spec_hash|
            direction, name = spec_hash.first
            case direction.to_sym
            when :desc
              Sequel.desc(name.to_sym)
            else
              Sequel.asc(name.to_sym)
            end
          end
          query = query.order(*order_clause)
          query
        end
        
        def self.count(query)
          query.count
        end
        
        def self.offset(query, offset)
          query.offset(offset)
        end

        def self.limit(query, limit)
          query.limit(limit)
        end        
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
praxis-2.0.pre.18 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.17 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.16 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.15 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.14 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.13 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.12 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.11 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.10 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.9 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.8 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.7 lib/praxis/extensions/pagination/sequel_pagination_handler.rb
praxis-2.0.pre.6 lib/praxis/extensions/pagination/sequel_pagination_handler.rb