class Wor::Paginate::Formatters::Base

Attributes

adapter[RW]
content[RW]
formatter[RW]
options[RW]

Public Class Methods

new(adapter, options = {}) click to toggle source
# File lib/wor/paginate/formatters/base.rb, line 10
def initialize(adapter, options = {})
  @adapter = adapter
  @options = options
end

Public Instance Methods

format() click to toggle source
# File lib/wor/paginate/formatters/base.rb, line 15
def format # rubocop: disable Metrics/MethodLength
  {
    page: serialized_content,
    count: count,
    total_pages: total_pages,
    total_count: options[:total_count] || total_count,
    current_page: current_page,
    previous_page: previous_page,
    next_page: next_page,
    next_page_url: page_url(next_page),
    previous_page_url: page_url(previous_page)
  }
end

Protected Instance Methods

current_page() click to toggle source
# File lib/wor/paginate/formatters/base.rb, line 33
def current_page
  adapter.page.to_i
end
current_url() click to toggle source
# File lib/wor/paginate/formatters/base.rb, line 55
def current_url
  options[:_current_url]
end
page_url(page) click to toggle source
# File lib/wor/paginate/formatters/base.rb, line 49
def page_url(page)
  return nil unless page

  replace_query_params(current_url, page: page)
end
paginated_content() click to toggle source
# File lib/wor/paginate/formatters/base.rb, line 37
def paginated_content
  @content ||= adapter.paginated_content
end
serialized_content() click to toggle source
# File lib/wor/paginate/formatters/base.rb, line 41
def serialized_content
  paginated_content.as_json
end
serializer() click to toggle source
# File lib/wor/paginate/formatters/base.rb, line 45
def serializer
  options[:each_serializer]
end