Class: Trolley::Utils::PaginatedArray

Inherits:
Array
  • Object
show all
Defined in:
lib/trolley/utils/PaginatedArray.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enum, page, pages, records) ⇒ PaginatedArray

Returns a new instance of PaginatedArray.



17
18
19
20
21
22
# File 'lib/trolley/utils/PaginatedArray.rb', line 17

def initialize(enum, page, pages, records)
  super(enum)
  @page = page
  @pages = pages
  @records = records
end

Instance Attribute Details

#pageObject

Returns the value of attribute page.



4
5
6
# File 'lib/trolley/utils/PaginatedArray.rb', line 4

def page
  @page
end

#pagesObject

Returns the value of attribute pages.



4
5
6
# File 'lib/trolley/utils/PaginatedArray.rb', line 4

def pages
  @pages
end

#recordsObject

Returns the value of attribute records.



4
5
6
# File 'lib/trolley/utils/PaginatedArray.rb', line 4

def records
  @records
end

Class Method Details

.from_response(response, klass) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/trolley/utils/PaginatedArray.rb', line 6

def self.from_response(response, klass)
  data = JSON.parse(response)

  enum = Utils::ResponseMapper.new(response, klass).build
  page = data.dig('meta', 'page')
  pages = data.dig('meta', 'pages')
  records = data.dig('meta', 'records')

  new(enum, page, pages, records)
end