Class: Workable::Collection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/workable/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data:, next_page_method:, transform_mapping:, root_key:, paging: nil) ⇒ Collection

Returns a new instance of Collection.



8
9
10
11
12
13
14
15
16
17
# File 'lib/workable/collection.rb', line 8

def initialize(data:, next_page_method:, transform_mapping:, root_key:, paging: nil)
  @data = data

  if paging
    @next_page         = paging['next']
    @next_page_method  = next_page_method
    @transform_mapping = transform_mapping
    @root_key          = root_key
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/workable/collection.rb', line 6

def data
  @data
end

Instance Method Details

#fetch_next_pageObject



23
24
25
26
27
# File 'lib/workable/collection.rb', line 23

def fetch_next_page
  return unless next_page?

  @next_page_method.call(@next_page, @transform_mapping, @root_key)
end

#next_page?Boolean

Returns:

  • (Boolean)


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

def next_page?
  !! @next_page
end