-
Notifications
You must be signed in to change notification settings - Fork 6
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
Codegen Output Demo - Config Constraints #150
Conversation
@@ -128,6 +128,13 @@ def validate_types! | |||
Hearth::Validator.validate_types!(validate_input, TrueClass, FalseClass, context: 'config[:validate_input]') | |||
end | |||
|
|||
def validate_range! |
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 think I might argue for changing the name of the validate_types!
method to be just validate!
(requires changing Hearth::Configuration) and then adding the validations for each member together. Eg:
validate_type(config_1)
validate_range(config_1)
some_other_future_validation(config_1)
validate_type(config_2)
validate_tyupe(config_3)
|
||
# draft of what validate_range *could* look like | ||
# valid_range param consists of min and max keys | ||
def self.validate_range(value, valid_range, context:) |
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.
What about using kwargs for min and max?
self.validate_range(value, min:, max:, context:)
Makes it easy to use like:
validate_range(value, min: 0, max: 10000)
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.
Ahh, yes. That would make sure we have :min
and :max
passed in.
def self.validate_range(value, valid_range, context:) | ||
# need to validate the valid_range object before proceeding | ||
# does it make sense us to use existing method - validate_type! | ||
valid_range.each { |context, value| self.validate_type!(value, Integer, context: context) } |
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 think we can probably skip validating that the inputs for min/max are correct since these aren't intended as customer input.
Description of changes:
Before I dive into the design/implementation work, I wanted to visualize what the end result could look like in Hearth and the
config.rb
file in the projected service.In this possible implementation, I'm thinking of adding a
validate_range
method to the Hearth'sValidator
modulePlease ignore the inconsistency of naming as this is just a rough draft.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.