Class: ActiveItem::Pagination::PaginatedResult

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_item/pagination.rb

Overview

Enumerable wrapper around a page of results with cursor metadata.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items:, next_cursor:, per_page:) ⇒ PaginatedResult

Returns a new instance of PaginatedResult.



32
33
34
35
36
# File 'lib/active_item/pagination.rb', line 32

def initialize(items:, next_cursor:, per_page:)
  @items = items
  @next_cursor = next_cursor
  @per_page = per_page
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



30
31
32
# File 'lib/active_item/pagination.rb', line 30

def items
  @items
end

#next_cursorObject (readonly)

Returns the value of attribute next_cursor.



30
31
32
# File 'lib/active_item/pagination.rb', line 30

def next_cursor
  @next_cursor
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



30
31
32
# File 'lib/active_item/pagination.rb', line 30

def per_page
  @per_page
end

Instance Method Details

#eachObject



46
# File 'lib/active_item/pagination.rb', line 46

def each(&) = items.each(&)

#empty?Boolean

Returns:

  • (Boolean)


50
# File 'lib/active_item/pagination.rb', line 50

def empty? = items.empty?

#has_more?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/active_item/pagination.rb', line 38

def has_more?
  !next_cursor.nil?
end

#lengthObject Also known as: size, count



47
# File 'lib/active_item/pagination.rb', line 47

def length = items.length

#pagination_metadataObject



42
43
44
# File 'lib/active_item/pagination.rb', line 42

def 
  { next_cursor: next_cursor, has_more: has_more?, per_page: per_page }
end

#to_aObject



51
# File 'lib/active_item/pagination.rb', line 51

def to_a = items