-
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
Expand Supports syntax (part deux) #21917
Expand Supports syntax (part deux) #21917
Conversation
extra note: I am wondering if we want a chain method, to base the supports either upon a parent feature or upon another feature. host, vm, and vm_or_template all base one supports upon a core feature. supports :stop do
if !supports?(:control)
unsupported_reason(:control)
elsif !vm_powered_on?
_('The VM is not powered on')
end
end
#
chain_supports(:stop, :control) { _('The VM is not powered on') unless vm_powered_on? }
#
supports(:stop => :control) { _('The VM is not powered on') unless vm_powered_on? } The two are more compact, but they don't necessarily read better. There are a few more ways to chain that seemed decent: supports(:reset) { unsupported_reason(:control) }
supports :stop do
unsupported_reason(:control) || vm_powered_on?
end Surprisingly, mixing Strings and |
f539d55
to
0114771
Compare
Implementing the boolean or string logic looks relatively straight forward: if !unsupported.key?(feature) && (result == false || result.kind_of?(String))
unsupported_reason_add(feature, reason_or_default(result))
end ==> moved into code to see if we like this or not |
622b8c4
to
fa4e175
Compare
cops did not update to new code push(es):
|
kicking cops |
fa4e175
to
3309af5
Compare
WIP:
|
Ok, sorry it took me some time to formulate this, but my fundamental problem with the approach is what you actually already laid out in the Implementation section of the OP. The return value from the block has multiple truthiness values that are contradictory and it's confusing to read. I see you wrote that it's not, but to me it's very confusing. Here's what I had started writing before reading your comment there, but it's a similar table: Given the word
I'll leave it up to @agrare to decide though, since this code falls almost entirely in the providers space. |
I almost did not introduce the But in the end of the day, the most important thing is to read the models and decide if it is clear. For me, the new way was easy to read, concise, and even mixing strings and booleans were clear. |
'Service template does not belong to a service catalog' | ||
elsif !display | ||
'Service template is not configured to be displayed' |
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.
Curious this is not i18n'd...we can do that in a follow up.
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.
we have a lot of these that are not internationalized''
9a4ca2d
to
6aacc9c
Compare
update:
|
6aacc9c
to
4e941ad
Compare
update:
|
We have dropped the case for boolean. REDACTED: true false syntax supports(:check_compliance:) { has_compliance_policies? } true returned means that this DOES support compliance REDACTED: ImplementationI added this as the last commit. The implementation is simple enough, but it is a little ambiguous/confusing if you think hard enough (too hard?).
The fact that a logical true can mean supported or not is a little confusing, and makes this option a little error prone. But in practice the code reads well enough. Introducing the boolean did simplify a few in core, and many more in the associated providers. Current implementationAs mentioned above, it was simpler to just remove the need for these cases. |
anyway |
@miq-bot cross-repo-tests /all |
From Pull Request: ManageIQ/manageiq#21917
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.
Fantastic work!
Thanks for the x-repo @agrare Can we merge this with that sporadic failure? |
@kbrock yeah API looks sporadic and ui-service failure looks unrelated (npm) but the ui-classic failure looks like it might be related https://github.com/ManageIQ/manageiq-cross_repo-tests/runs/7414529833?check_suite_focus=true#step:6:2847 |
4e941ad
to
783ced7
Compare
update:
|
Checked commits kbrock/manageiq@ac917f0~...783ced7 with ruby 2.6.9, rubocop 1.19.1, haml-lint 0.35.0, and yamllint |
@miq-bot cross-repo-tests ManageIQ/manageiq-ui-classic#8366 |
From Pull Request: ManageIQ/manageiq#21917
Glad to see this over the finish line! |
Part of project: #21179
Also merge: ManageIQ/manageiq-ui-classic#8366
This is based upon a conversation started by @chessbyte : #21269 which started in vmware-provider
It came up a few times and now that we have reworked supports a bit, it seemed like a good time to see revisit and see if this new syntax makes more sense.
Ideas in discussion
Before
Most of the
supports_not
blocks have been transitioned to use the default reason:supports :feature
supports_not :feature
supports_not :feature, :reason => ""
supports :feature do ; end
String Syntax
This gives the end user more of an understanding as to why this operation is not available.
Half of the time this is an
if
/elsif
chain.Returning
nil
means that this feature is supported.Of the reasons given, a quarter could just use the default value:
Boolean Syntax
We have dropped the use of returning a boolean. Most of those cases have been converted to the standard
supports
/supports_not
syntax.