Class: HALDecorator::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/hal_decorator/pagination.rb

Overview

TODO: Support Kaminari and Will_paginate

Defined Under Namespace

Classes: Uri

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serialized, collection) ⇒ Pagination

Returns a new instance of Pagination.



53
54
55
56
57
# File 'lib/hal_decorator/pagination.rb', line 53

def initialize(serialized, collection)
  @serialized = serialized
  @collection = collection
  @self_uri = Uri.parse serialized.dig(:_links, :self, :href)
end

Class Method Details

.paginate!(serialized, collection) ⇒ Object



49
50
51
# File 'lib/hal_decorator/pagination.rb', line 49

def self.paginate!(serialized, collection)
  new(serialized, collection).call
end

Instance Method Details

#callObject



59
60
61
62
63
64
# File 'lib/hal_decorator/pagination.rb', line 59

def call
  return unless should_paginate?
  add_query_to_self
  add_prev_link
  add_next_link
end