-
Notifications
You must be signed in to change notification settings - Fork 900
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
Update API to use descendant_get to return valid types #14521
Update API to use descendant_get to return valid types #14521
Conversation
|
||
module ClassMethods | ||
def class_from_string(type) | ||
return self if type == to_s || type.nil? |
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.
@Fryguy wasn't sure we should default to returning itself if type is nil. We did this in Authentication, not sure we should generalize that though. thoughts?
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 like the class_from_string method as it seems to imply you can get any class, but you really can't. Perhaps, descendant_by_name
or descendant_for
? This seems to imply you will get the descendant class, and it mirrors the method named descendants
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.
haha, I didn't see this until now. Honest.
This pull request is not mergeable. Please rebase and repush. |
@Fryguy bump |
task_id = type.create_in_provider_queue(manager.id, data.except('manager_resource').deep_symbolize_keys) | ||
|
||
type = "#{manager.type}::ConfigurationScriptSource" | ||
klass = ConfigurationScriptSource.class_from_string(type) |
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 had to look at the tests to know what class_from_string did.
descendent_class_from_name
Naming is hard. Technically, it should be descendent or self but that's just too many words.
I like the idea, just not sure about the name.
Summary of names:
I think I like the last one the best, personally. It takes @jrafanie's but removes the _class bit since it's not needed, just as the |
The ancestry gem differentiates this with the word |
👍 to or |
@@ -118,15 +119,6 @@ def self.build_credential_options | |||
end | |||
end | |||
|
|||
def self.class_from_request_data(data) |
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 didn't look, are there no other callers? Can you grep not only manageiq but all providers to make sure we update all callers?
I usually do this now that we have so many extracted repos..
$ bundle show rails
/Users/joerafaniello/.gem/ruby/2.4.1/gems/rails-5.0.4
Take that path and basically grep the grandparent directory so it includes not only gems but bundler git gems:
grep -ir "class_from_request_data" /Users/joerafaniello/.gem/ruby/2.4.1
Or something like that
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.
@jrafanie yeah this is the only caller - this was a method I created for the API back in March to be replaced by this update
Nice, I like it. |
will need new version of |
There's one other PR in the works on more_core...just want to get that one over the finish line as well before cutting a release. cc @bdunne |
@jntullo Can you update the minimum version of |
Checked commits jntullo/manageiq@3ba7f66~...25d4e5b with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Mixin that returns the correct subclass from the specified string, or raises and error if it is not a subclass of that type.
Part of a refactoring effort for #14217
@miq-bot assign @Fryguy
@miq-bot add_label refactoring, wip