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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions codegen/projections/white_label/lib/white_label/config.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions hearth/lib/hearth/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,20 @@ def self.validate_unknown!(struct, params, context:)
raise ArgumentError,
"Unexpected members: [#{unknown.join(', ')}]"
end

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

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


return if value.between?(valid_range[:min], valid_range[:max])

raise ArgumentError,
"Expected #{context} to be between " \
"#{minimum} to #{maximum}, got #{value}."
end

end
end
Loading