Module: Esse::Kaminari::Pagination::SearchQuery
- Defined in:
- lib/esse/kaminari/pagination.rb
Class Method Summary collapse
Instance Method Summary collapse
- #limit(value) ⇒ Object
- #limit_value ⇒ Object
- #offset(value) ⇒ Object
- #offset_value ⇒ Object
- #paginated_results ⇒ Object
- #total_count ⇒ Object
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/esse/kaminari/pagination.rb', line 7 def self.included(base) base.__send__ :include, ::Kaminari::PageScopeMethods base.__send__ :extend, Forwardable base.__send__ :def_delegators, :_kaminari_config, :default_per_page, :max_per_page, :max_pages base.class_eval <<-RUBY, __FILE__, __LINE__ + 1 # Define the `page` Kaminari method # # @param [Integer] page # @return [self] def #{::Kaminari.config.page_method_name}(num=nil) reset! @page = [num.to_i, 1].max @per_page ||= limit_value definition.update( size: @per_page, from: @per_page * (@page - 1), ) self end RUBY end |
Instance Method Details
#limit(value) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/esse/kaminari/pagination.rb', line 49 def limit(value) return self if value.to_i <= 0 reset! @per_page = value.to_i definition.update(size: @per_page) definition.update(from: @per_page * (@page - 1)) if @page self end |
#limit_value ⇒ Object
33 34 35 |
# File 'lib/esse/kaminari/pagination.rb', line 33 def limit_value (raw_limit_value || default_per_page).to_i end |
#offset(value) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/esse/kaminari/pagination.rb', line 59 def offset(value) return self if value.to_i < 0 reset! @page = nil definition.update(from: value.to_i) self end |
#offset_value ⇒ Object
37 38 39 |
# File 'lib/esse/kaminari/pagination.rb', line 37 def offset_value raw_offset_value.to_i end |
#paginated_results ⇒ Object
45 46 47 |
# File 'lib/esse/kaminari/pagination.rb', line 45 def paginated_results ::Kaminari.paginate_array(response.hits, limit: limit_value, offset: offset_value, total_count: total_count) end |
#total_count ⇒ Object
41 42 43 |
# File 'lib/esse/kaminari/pagination.rb', line 41 def total_count response.total end |