-
Notifications
You must be signed in to change notification settings - Fork 100
Add string based time duration support. #194
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
Add string based time duration support. #194
Conversation
def self.coerce_in_seconds(value, unit) | ||
matched = NUMBERS_RE.match(value) | ||
if matched.nil? | ||
return "Value '#{value}' is not a valid duration string e.g. 200 usec, 250ms, 60 sec, 18h, 21.5d, 1 day, 2w, 6 weeks" |
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 I understand the reason for returning a string to represent an error condition. why not just raise an exception? I think it will make the error handling code much easier to read and follow?
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 just followed the pattern from validate_value
in the config dsl mixin.
I will improve it.
This is neat. I am wondering what the plan would be to make this generic and usable from other plugins? |
@colinsurprenant As to making it reusable, I would like to do so but it depends on what the core team do with the Java Plugin API WRT custom validation and having an interface to implement for a such a class. |
Or the generic part of could be extracted as a gem, and then it could be reused elsewhere too. I'll let you followup on this if you feel this could bring value. So the only conceptual problem I see is that this relies on swapping implementation details and could possibly break upon upgrading core. I wonder if we could avoid this here? |
So there are three parts to the mechanism (same with the custom validators in jdbc_static).
1 Is definitely susceptible to a change in core. IMO, 1 need to be in the Plugin API with a validation hooks style registry. |
@guyboertje WDYT in opening a followup issue for this - I think we should keep tab on this and have some kind of strategy to prevent future regressions because no one realized that some plugins were depending on the validation implementation. |
74b3d6a
to
78651a8
Compare
LGTM |
Hi @guyboertje Thanks for this great enhancement ! Given that for some options, types and default values have changed, it would be great to also update documentation, I mean : docs/index.asciidoc |
Sorry for my remark : I just realized it is already done in the following PR. |
Fixes #187