Class: FieldView::ListObject

Inherits:
Requestable show all
Includes:
Enumerable
Defined in:
lib/fieldview/list_object.rb

Instance Attribute Summary collapse

Attributes inherited from Requestable

#auth_token

Instance Method Summary collapse

Constructor Details

#initialize(listable, auth_token, data, http_status, next_token: nil, limit: 100) ⇒ ListObject

Returns a new instance of ListObject.



7
8
9
10
11
12
13
14
# File 'lib/fieldview/list_object.rb', line 7

def initialize(listable, auth_token, data, http_status, next_token: nil, limit: 100)
  @listable = listable
  @data = data
  @last_http_status = http_status
  @next_token = next_token
  @limit = limit
  super(auth_token)
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/fieldview/list_object.rb', line 4

def data
  @data
end

#last_http_statusObject (readonly)

Returns the value of attribute last_http_status.



4
5
6
# File 'lib/fieldview/list_object.rb', line 4

def last_http_status
  @last_http_status
end

#limitObject

Returns the value of attribute limit.



3
4
5
# File 'lib/fieldview/list_object.rb', line 3

def limit
  @limit
end

#listableObject (readonly)

Returns the value of attribute listable.



4
5
6
# File 'lib/fieldview/list_object.rb', line 4

def listable
  @listable
end

#next_tokenObject (readonly)

Returns the value of attribute next_token.



4
5
6
# File 'lib/fieldview/list_object.rb', line 4

def next_token
  @next_token
end

Instance Method Details

#each(&blk) ⇒ Object



16
17
18
# File 'lib/fieldview/list_object.rb', line 16

def each(&blk)
  self.data.each(&blk)
end

#has_more?Boolean

alias for more_pages

Returns:

  • (Boolean)


28
29
30
# File 'lib/fieldview/list_object.rb', line 28

def has_more?()
  return self.more_pages?()
end

#more_pages?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/fieldview/list_object.rb', line 32

def more_pages?()
  return Util.http_status_is_more_in_list?(self.last_http_status)
end

#next_page!Object



20
21
22
23
24
25
# File 'lib/fieldview/list_object.rb', line 20

def next_page!()
  return if !self.more_pages?()
  new_list = @listable.list(auth_token, limit: self.limit, next_token: self.next_token)
  initialize(new_list.listable, new_list.auth_token, 
    new_list.data, new_list.last_http_status, next_token: new_list.next_token, limit: new_list.limit)
end

#restart!Object



36
37
38
39
40
# File 'lib/fieldview/list_object.rb', line 36

def restart!()
  @last_http_status = nil
  @next_token = nil
  next_page!()
end