class Vultr::Collection
Attributes
Public Class Methods
Source
# File lib/vultr/collection.rb, line 6 def self.from_response(response, key:, type:) body = response.body new( data: body[key].map { |attrs| type.new(attrs) }, total: body.dig("meta", "total"), next_cursor: body.dig("meta", "links", "next"), prev_cursor: body.dig("meta", "links", "prev") ) end
Source
# File lib/vultr/collection.rb, line 16 def initialize(data:, total:, next_cursor:, prev_cursor:) @data = data @total = total @next_cursor = next_cursor.empty? ? nil : next_cursor @prev_cursor = prev_cursor.empty? ? nil : prev_cursor end
Public Instance Methods
Source
# File lib/vultr/collection.rb, line 23 def each return enum_for(:each) unless block_given? @data.each(&block) end