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

Overwriting the methods retrieve! and exists? in the volume #274

Merged
merged 4 commits into from
Sep 28, 2017

Conversation

aalexmonteiro
Copy link
Contributor

Description

Overwriting the methods retrieve! and exists? in the volume.

Issues Resolved

#273

Check List

  • [] New functionality includes testing.
    • All tests pass ($ rake test).
  • New functionality has been documented in the README if applicable.
    • New functionality has been thoroughly documented in the examples (please include helpful comments).
  • Changes are documented in the CHANGELOG.

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
Copy link
Contributor

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?
Copy link
Member

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.

Copy link
Contributor Author

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!.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

@fgbulsoni fgbulsoni Sep 27, 2017

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
Copy link
Member

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.

Copy link
Contributor Author

@aalexmonteiro aalexmonteiro Sep 27, 2017

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.

Copy link
Contributor

@fgbulsoni fgbulsoni Sep 27, 2017

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
Copy link
Contributor

@fgbulsoni fgbulsoni Sep 27, 2017

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

Copy link
Member

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
Copy link
Contributor

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] }]
Copy link
Contributor

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]

@aalexmonteiro
Copy link
Contributor Author

With your suggestions, the code is better now. Thanks guys. Can you review again, please?

Copy link
Contributor

@fgbulsoni fgbulsoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:octocat:

Copy link
Contributor

@fgbulsoni fgbulsoni left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the unreleased part

Copy link
Contributor

@fgbulsoni fgbulsoni left a 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 👍

@aalexmonteiro aalexmonteiro merged commit ceb3514 into master Sep 28, 2017
@aalexmonteiro aalexmonteiro deleted the enhancement/find_volume_in_api500 branch September 28, 2017 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants