Class: ScriptedClient::Collection

Inherits:
ActiveResource::Collection
  • Object
show all
Defined in:
lib/scripted_client/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed = {}) ⇒ Collection

Returns a new instance of Collection.



6
7
8
9
10
# File 'lib/scripted_client/collection.rb', line 6

def initialize(parsed = {})
  @elements = parsed['data']
  paging = parsed['paging']
  @next_page = paging['next_cursor'] if paging && paging['has_next']
end

Instance Attribute Details

#next_pageObject

Returns the value of attribute next_page.



4
5
6
# File 'lib/scripted_client/collection.rb', line 4

def next_page
  @next_page
end

Instance Method Details

#has_next?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/scripted_client/collection.rb', line 19

def has_next?
  next_page.present?
end

#nextObject



12
13
14
15
16
17
# File 'lib/scripted_client/collection.rb', line 12

def next
  fail 'No more pages' unless has_next?
  resource_class.all(
    params: original_params.merge(next_cursor: next_page)
  )
end