Droplet actions last? method crashes
Opened this issue · 2 comments
Trying to call such code:
client = DropletKit::Client.new(access_token: 'TOKEN')
print client.droplets.actions(id: 'DROPLET_ID').last?.status
and get output:
Traceback (most recent call last):
1: from ./script.sh:5:in `block (2 levels) in <main>'
/Library/Ruby/Gems/2.6.0/gems/droplet_kit-3.3.1/lib/droplet_kit/paginated_resource.rb:47:in `last?': undefined method `zero?' for nil:NilClass (NoMethodError)
Looks like error
Thanks for the report @v-vodyanov, I'll look into this right now.
Hey @v-vodyanov, I've just released version 3.5.1 that fixes the crash.
With that said, the last?
method was designed to be used by our pagination logic to tell if we're on the last page of results or not, so calling,
client.droplets.actions(id: 'DROPLET_ID').last?.status
will still result in an error, as last?
returns a boolean.
Because we're using Ruby's Enumerable
mixin for this pagination logic, there's no support for a last
method that returns the final element in the collection, as the Enumerable
mixin assumes that a collection may have an infinite number of elements. There may be a way for us to add this to the PaginatedResource
class ourselves though, so if you're interested in that, please feel free to open a new issue.