-
-
Save m-o-e/f0bc661afd4ec2de48e18ae8ef15a6c1 to your computer and use it in GitHub Desktop.
This file contains 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
class Lux::Int32Param < Lux::Param | |
# Return the parsed/casted, validated value or raise a ValidationError. | |
# Do not allow any other Exceptions to raise from here (that would cause a HTTP 500). | |
def initialize(@minimum : Int32? = nil, | |
@maximum : Int32? = nil) | |
end | |
def openapi(name, source, description, required) | |
# todo | |
nil | |
end | |
def from_string(value) | |
begin | |
retval = Int32.new(value) | |
rescue | |
error!("format", "int32", "must be a number") | |
end | |
if @maximum && retval > @maximum.not_nil! | |
error!("maximum", @maximum.not_nil!, "is too big (allowed range: #{@minimum}-#{@maximum})") | |
elsif @minimum && retval < @minimum.not_nil! | |
error!("minimum", @minimum.not_nil!, "is too small (allowed range: #{@minimum}-#{@maximum})") | |
end | |
retval | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment