-
Notifications
You must be signed in to change notification settings - Fork 16
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
Overwriting the methods retrieve! and exists? in the volume #274
Conversation
CHANGELOG.md
Outdated
## v5.0.5(unreleased) | ||
|
||
#### Bug fixes & Enhancements | ||
- [#273](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/273) Find a volume using the retrieve! and exists? methods on the API500 before a post |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps something in the lines of: 'retrieve!' and 'exists?' methods return false for existing Volumes on API500
?
The issue title as it is now might not be super clear.
# Check if a resource exists | ||
# @note one of the UNIQUE_IDENTIFIERS, e.g. name or uri or properties['name'], must be specified in the resource | ||
# @return [Boolean] Whether or not resource exists | ||
def exists? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method does same thing that retrieve!
method, right?
Maybe can be good call the retrieve!
method here (Just do not use the self instance to call retrieve!
, you can use a temp variable to that), avoiding write the "same" code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case I think not, because exists?
does not set the resource. Perhaps the opposite, the exists?
being called within retrieve!
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using exists?
within retrieve is likely the better alternative indeed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see now. If I want to reuse only two first rows of each method. I need to call retrieve!
inside exists?
, because I need a result to set up the data. Can I use the Ricardo's suggestion, which uses a temporary variable to avoid setting the data when exists?
is called. I don't see big gains from this change. But it's okay, I'll do this and see what the code will look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do not see big gains, keep the code as is it. No problem for me. =)
Important is the behavior to be ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see big gains from this change. But it's okay, I'll do this and see what the code will look like.
Ops, true. Since exists?
will only return a boolean instead of the resource, this is actually bad.
# Gets the volume | ||
# @raise [OneviewSDK::IncompleteResource] if the name parameter is not set | ||
# @return [Array] the array of volumes | ||
def find |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The find
name of this method seems generic, maybe marking that as a private or renaming the method can be better. Or, I guess be good option, you can put the code "to find by name" (It is what this method does) into the retrieve!
method, it is a simples code and it is used just in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is already a private method. But I can rename it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what a good name for this could be though, find_by_name_in_properties
? Kinda long, but...
# @return [Boolean] Whether or not resource exists | ||
def exists? | ||
return super unless @data['properties'] | ||
results = find |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
find.size == 1 ? true : false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or just:
find.size == 1
def retrieve! | ||
return super unless @data['properties'] | ||
results = find | ||
if results.size == 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return false unless results.size == 1
set_all(results.first.data)
true
# @raise [OneviewSDK::IncompleteResource] if the name parameter is not set | ||
# @return [Array] the array of volumes | ||
def find | ||
@data['properties'] = Hash[@data['properties'].map { |k, v| [k.to_s, v] }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to be converting the whole @data['properties']
here?
This is likely less expensive and will accomplish the same thing:
name = @data['name'] || @data[:name]
With your suggestions, the code is better now. Thanks guys. Can you review again, please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While all the code is good and all, it is likely better to prepare to release this right away since Chef is depending on it, right?
CHANGELOG.md
Outdated
@@ -1,3 +1,8 @@ | |||
## v5.0.5(unreleased) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the unreleased part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, feel free to release 👍
Description
Overwriting the methods retrieve! and exists? in the volume.
Issues Resolved
#273
Check List
$ rake test
).