Class: ActiveModelSerializers::Adapter::JsonApi::PaginationLinks

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

Constant Summary collapse

MissingSerializationContextError =
Class.new(KeyError)
FIRST_PAGE =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, adapter_options) ⇒ PaginationLinks

Returns a new instance of PaginationLinks.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_model_serializers/adapter/json_api/pagination_links.rb', line 12

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

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



10
11
12
# File 'lib/active_model_serializers/adapter/json_api/pagination_links.rb', line 10

def collection
  @collection
end

#contextObject (readonly)

Returns the value of attribute context.



10
11
12
# File 'lib/active_model_serializers/adapter/json_api/pagination_links.rb', line 10

def context
  @context
end

Instance Method Details

#as_jsonObject



24
25
26
27
28
29
30
31
32
# File 'lib/active_model_serializers/adapter/json_api/pagination_links.rb', line 24

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