Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return bonafide model objects where possible for nested attributes #111

Closed
djberg96 opened this issue Nov 13, 2015 · 3 comments
Closed

Return bonafide model objects where possible for nested attributes #111

djberg96 opened this issue Nov 13, 2015 · 3 comments

Comments

@djberg96
Copy link
Collaborator

For example, if I want to get a list of network interfaces for a virtual machine I could do this:

vm.properties.network_profile.network_interfaces.each{ |n| ... }

The problem is that the objects returned by that only have the :id attribute because that's what the JSON has. However, we have NetworkInterface model objects as well.

So, instead of just returning a simple object with an :id field, provide a generic method to call that returns a real model object if we have one that wraps it. The :id field should still exist, too, in case users want to use the original value. So, something like:

vm.properties.network_profile.network_interfaces.each{ |n| n.model ... }
@djberg96
Copy link
Collaborator Author

djberg96 commented Mar 8, 2016

Maybe an Enumerable#each_model method?

@djberg96
Copy link
Collaborator Author

Another option would be to either modify the ResourceGroupBasedService#get method to accept an id string, or to provide a find_by_id method that smartly determined which Service#get method to call.

@djberg96
Copy link
Collaborator Author

To that end I've submitted this PR: #225

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant