Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

jterapin
Copy link
Contributor

@jterapin jterapin commented Jul 27, 2023

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's Validator module

Please 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.

@@ -128,6 +128,13 @@ def validate_types!
Hearth::Validator.validate_types!(validate_input, TrueClass, FalseClass, context: 'config[:validate_input]')
end

def validate_range!
Copy link
Contributor

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:)
Copy link
Contributor

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)

Copy link
Contributor Author

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) }
Copy link
Contributor

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.

@jterapin jterapin closed this Jul 31, 2023
@jterapin jterapin deleted the config_constraint_draft branch July 31, 2023 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants