Class: Spree::Api::PagyCollection

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Enumerable
Defined in:
app/paginators/spree/api/paginate.rb

Overview

Wrapper providing Kaminari-compatible interface for CollectionOptionsHelpers Includes Enumerable so jsonapi-serializer detects it as a collection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records, pagy) ⇒ PagyCollection

Returns a new instance of PagyCollection.



41
42
43
44
# File 'app/paginators/spree/api/paginate.rb', line 41

def initialize(records, pagy)
  super(records)
  @pagy = pagy
end

Instance Attribute Details

#pagyObject (readonly)

Returns the value of attribute pagy.



39
40
41
# File 'app/paginators/spree/api/paginate.rb', line 39

def pagy
  @pagy
end

Instance Method Details

#each(&block) ⇒ Object

Enumerable requires #each to be defined



47
48
49
# File 'app/paginators/spree/api/paginate.rb', line 47

def each(&block)
  __getobj__.each(&block)
end

#next_pageObject



51
52
53
# File 'app/paginators/spree/api/paginate.rb', line 51

def next_page
  @pagy.next
end

#prev_pageObject



55
56
57
# File 'app/paginators/spree/api/paginate.rb', line 55

def prev_page
  @pagy.previous
end

#total_countObject



63
64
65
# File 'app/paginators/spree/api/paginate.rb', line 63

def total_count
  @pagy.count
end

#total_pagesObject



59
60
61
# File 'app/paginators/spree/api/paginate.rb', line 59

def total_pages
  @pagy.pages
end