Skip to content

Instantly share code, notes, and snippets.

@m-o-e

m-o-e/int32.cr Secret

Created April 10, 2022 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m-o-e/f0bc661afd4ec2de48e18ae8ef15a6c1 to your computer and use it in GitHub Desktop.
Save m-o-e/f0bc661afd4ec2de48e18ae8ef15a6c1 to your computer and use it in GitHub Desktop.
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