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:, result:, 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:, result:, list_property:, klass:)
  @client = client
  @result = result
  @list_property = list_property
  @next_page_uri = @result['next_page_uri']
  @uri = @result['uri']
  @items = @result[list_property].map do |item|
    klass.new(client: client, result: item)
  end
  @iter = NgrokAPI::PagedIterator.new(
    client: client,
    page: self,
    list_property: list_property,
    danger: danger
  )
end

Instance Attribute Details

#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

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
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)
  @result == other.result
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
  @result.to_s
end