class ActiveModelSerializers::Adapter::JsonApi::PaginationLinks

def as_json

def as_json
  {
    self:  location_url,
    first: first_page_url,
    prev:  prev_page_url,
    next:  next_page_url,
    last:  last_page_url
  }
end

def first_page_url

def first_page_url
  url_for_page(1)
end

def initialize(collection, adapter_options)

def initialize(collection, adapter_options)
  @collection = collection
  @adapter_options = adapter_options
  @context = adapter_options.fetch(:serialization_context) do
    fail MissingSerializationContextError, <<-EOF.freeze
::PaginationLinks requires a ActiveModelSerializers::SerializationContext.
pass a ':serialization_context' option or
e CollectionSerializer#paginated? to return 'false'.
    EOF
  end
end

def last_page_url

def last_page_url
  if collection.total_pages == 0
    url_for_page(FIRST_PAGE)
  else
    url_for_page(collection.total_pages)
  end
end

def location_url

def location_url
  url_for_page(collection.current_page)
end

def next_page_url

def next_page_url
  return nil if collection.total_pages == 0 || collection.current_page == collection.total_pages
  url_for_page(collection.next_page)
end

def per_page

def per_page
  @per_page ||= collection.try(:per_page) || collection.try(:limit_value) || collection.size
end

def prev_page_url

def prev_page_url
  return nil if collection.current_page == FIRST_PAGE
  url_for_page(collection.current_page - FIRST_PAGE)
end

def query_parameters

def query_parameters
  @query_parameters ||= context.query_parameters
end

def request_url

def request_url
  @request_url ||= context.request_url
end

def url(options = {})

def url(options = {})
  @url ||= options.fetch(:links, {}).fetch(:self, nil) || request_url
end

def url_for_page(number)

def url_for_page(number)
  params = query_parameters.dup
  params[:page] = { size: per_page, number: number }
  "#{url(adapter_options)}?#{params.to_query}"
end