Class: ActiveModel::Serializer::Adapter::JsonApi::PaginationLinks

Inherits:
Object
  • Object
show all
Defined in:
lib/active_model/serializer/adapter/json_api/pagination_links.rb

Constant Summary collapse

FIRST_PAGE =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, context) ⇒ PaginationLinks

Returns a new instance of PaginationLinks.



6
7
8
9
# File 'lib/active_model/serializer/adapter/json_api/pagination_links.rb', line 6

def initialize(collection, context)
  @collection = collection
  @context = context
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



4
5
6
# File 'lib/active_model/serializer/adapter/json_api/pagination_links.rb', line 4

def collection
  @collection
end

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/active_model/serializer/adapter/json_api/pagination_links.rb', line 4

def context
  @context
end

Instance Method Details

#serializable_hash(options = {}) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/active_model/serializer/adapter/json_api/pagination_links.rb', line 11

def serializable_hash(options = {})
  pages_from.each_with_object({}) do |(key, value), hash|
    params = query_parameters.merge(page: { number: value, size: collection.size }).to_query

    hash[key] = "#{url(options)}?#{params}"
  end
end