ninech / netbox-client-ruby

A ruby client library for Netbox v2.
MIT License
24 stars 21 forks source link

calling a random method no longer tries to load the data when the :id has not been set #41

Closed TvL2386 closed 3 years ago

TvL2386 commented 3 years ago

Hi, this fixes issue #39 .

The problem seemed to be that calling a random method (like :flatten), would cause the entity to be retrieved from netbox whether the entity had an :id or not. In my case, the newly initialized entities weren't saved yet causing a LocalError to be raised.

I had to change the functionality. When !ids_set?, the instance won't be loaded from netbox but will raise NoMethodError instead of LocalError. It seems more accurate imho.

This fixes [Entity.new].flatten, because NoMethodError will now be raised.

I'm curious as to what you think of this change. Please keep in mind I have little experience with TDD.

Kind regards, tvl2386

thde commented 3 years ago

LGTM. Thanks for the merge request! :)