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.



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

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.



10
11
12
# File 'lib/ngrokapi/models/listable.rb', line 10

def attrs
  @attrs
end

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/ngrokapi/models/listable.rb', line 10

def client
  @client
end

#itemsObject (readonly)

Returns the value of attribute items.



10
11
12
# File 'lib/ngrokapi/models/listable.rb', line 10

def items
  @items
end

#iterObject (readonly)

Returns the value of attribute iter.



10
11
12
# File 'lib/ngrokapi/models/listable.rb', line 10

def iter
  @iter
end

#klassObject (readonly)

Returns the value of attribute klass.



10
11
12
# File 'lib/ngrokapi/models/listable.rb', line 10

def klass
  @klass
end

#list_propertyObject (readonly)

Returns the value of attribute list_property.



10
11
12
# File 'lib/ngrokapi/models/listable.rb', line 10

def list_property
  @list_property
end

#next_page_uriObject (readonly)

Returns the value of attribute next_page_uri.



10
11
12
# File 'lib/ngrokapi/models/listable.rb', line 10

def next_page_uri
  @next_page_uri
end

#uriObject (readonly)

Returns the value of attribute uri.



10
11
12
# File 'lib/ngrokapi/models/listable.rb', line 10

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
# File 'lib/ngrokapi/models/listable.rb', line 44

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

#eachObject



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

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

#to_sObject



48
49
50
# File 'lib/ngrokapi/models/listable.rb', line 48

def to_s
  @attrs.to_s
end