This repository was archived by the owner on Nov 6, 2024. It is now read-only.
Open
Conversation
getand
approved these changes
Dec 23, 2020
Contributor
getand
left a comment
There was a problem hiding this comment.
A few suggestions on naming. What I would like to have though is a test that proves an error is raised in case both optional and required option are given. Otherwise looks good.
| has_required_option = options.key?(:required) | ||
| has_optional_option = options.key?(:optional) | ||
|
|
||
| raise Errors::InvalidOptions, "Can't make a node optional and required in the same time" if has_required_option && has_optional_option |
Contributor
There was a problem hiding this comment.
Suggested change
| raise Errors::InvalidOptions, "Can't make a node optional and required in the same time" if has_required_option && has_optional_option | |
| raise Errors::InvalidOptions, "Can't make a node optional and required at the same time" if has_required_option && has_optional_option |
| end | ||
|
|
||
| def resolve_required_or_optional_option | ||
| has_required_option = options.key?(:required) |
Contributor
There was a problem hiding this comment.
Suggested change
| has_required_option = options.key?(:required) | |
| required_option_provided = options.key?(:required) |
|
|
||
| def resolve_required_or_optional_option | ||
| has_required_option = options.key?(:required) | ||
| has_optional_option = options.key?(:optional) |
Contributor
There was a problem hiding this comment.
Suggested change
| has_optional_option = options.key?(:optional) | |
| optional_option_provided = options.key?(:optional) |
|
|
||
| if required.respond_to?(:call) | ||
| # When a node is conditionally required we make it optional and add a validator to the parent to check | ||
| # that it's there when the option apply. |
Contributor
There was a problem hiding this comment.
Suggested change
| # that it's there when the option apply. | |
| # that it's there when the option applies. |
Contributor
|
Also please do not forget to update the readme with an example. ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Nodes within schema can not accept required option. This option makes the node conditionally required. Currently we do not allow a node to be conditionally required and optional in the same time.