Class: NgrokAPI::Models::Listable

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ngrokapi/models/listable.rb

Overview

A resource representing multiple instances from a given "list" API call

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(danger: false, client:, attrs:, list_property:, klass:) ⇒ Listable

Returns a new instance of Listable.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ngrokapi/models/listable.rb', line 21

def initialize(danger: false, client:, attrs:, list_property:, klass:)
  @client = client
  @attrs = attrs
  @list_property = list_property
  @next_page_uri = @attrs['next_page_uri']
  @uri = @attrs['uri']
  @items = @attrs[list_property].map do |item|
    klass.new(client: client, attrs: item)
  end
  @iter = NgrokAPI::PagedIterator.new(
    client: client,
    page: self,
    list_property: list_property,
    danger: danger
  )
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



12
13
14
# File 'lib/ngrokapi/models/listable.rb', line 12

def attrs
  @attrs
end

#clientObject (readonly)

Returns the value of attribute client.



12
13
14
# File 'lib/ngrokapi/models/listable.rb', line 12

def client
  @client
end

#itemsObject (readonly)

Returns the value of attribute items.



12
13
14
# File 'lib/ngrokapi/models/listable.rb', line 12

def items
  @items
end

#iterObject (readonly)

Returns the value of attribute iter.



12
13
14
# File 'lib/ngrokapi/models/listable.rb', line 12

def iter
  @iter
end

#klassObject (readonly)

Returns the value of attribute klass.



12
13
14
# File 'lib/ngrokapi/models/listable.rb', line 12

def klass
  @klass
end

#list_propertyObject (readonly)

Returns the value of attribute list_property.



12
13
14
# File 'lib/ngrokapi/models/listable.rb', line 12

def list_property
  @list_property
end

#next_page_uriObject (readonly)

Returns the value of attribute next_page_uri.



12
13
14
# File 'lib/ngrokapi/models/listable.rb', line 12

def next_page_uri
  @next_page_uri
end

#uriObject (readonly)

Returns the value of attribute uri.



12
13
14
# File 'lib/ngrokapi/models/listable.rb', line 12

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Object



46
47
48
# File 'lib/ngrokapi/models/listable.rb', line 46

def ==(other)
  @attrs == other.attrs
end

#eachObject



38
39
40
41
42
43
44
# File 'lib/ngrokapi/models/listable.rb', line 38

def each
  item = @iter.get_next
  while item
    yield item
    item = @iter.get_next
  end
end

#to_sObject



50
51
52
# File 'lib/ngrokapi/models/listable.rb', line 50

def to_s
  @attrs.to_s
end