Sha256: 8b7a073d50acd5311a4b5da7b5658836c91dfc392eda4319ca9c640394374d25
Contents?: true
Size: 839 Bytes
Versions: 2
Compression:
Stored size: 839 Bytes
Contents
# frozen_string_literal: true require_relative '../base_adapter' require_relative '../base_processor' class ActiveSet class PaginateProcessor < BaseProcessor class ActiveRecordAdapter < BaseAdapter def process return return_set unless @set.respond_to? :to_sql return_set(paginated_set) end private def paginated_set return @set.none if @set.count <= page_size && page_number > 1 @set.limit(page_size).offset(page_offset) end def page_offset return 0 if page_number == 1 page_size * page_number end def page_size @instruction.value end def page_number num = @instruction.attribute.to_i return 1 if (num - 1).negative? return 1 if (num - 1).zero? num end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
activeset-0.5.3 | lib/active_set/processors/paginate/active_record_adapter.rb |
activeset-0.5.2 | lib/active_set/processors/paginate/active_record_adapter.rb |