module Parameters
Builds parameter models for filtering, conversion, and validation.
Nested Classes and Modules
class BuilderBuilds immutable parameter models using a field DSL.
class EnumerationConverts an exact set of input values to corresponding output values.
class ErrorA validation error associated with a specific argument path.
class ValidationErrorRaised when parsed parameters are invalid.
class FieldCommon behavior for fields in a parameter model.
class ModelAn immutable model for parsing, filtering, and validating parameters.
class ResultThe result of parsing and validating content parameters.
class TypeConverts input values to a specific application type.
class UploadA field-constrained streaming upload.
module ValueInternal values carry upload outcomes from streaming parsing into field validation.
Definitions
TYPES
The built-in parameter type conversions.
Implementation
TYPES = {
Integer => ->(value) do
# Reject non-string values rather than relying on implicit numeric coercion:
unless value.is_a?(String)
raise TypeError
end
Integer(value, 10)
end,
Float => ->(value){Float(value)},
}.freeze
def self.build(parser: Parser.default, types: TYPES, strict: true, &block)
Build an immutable parameter model.
Signature
-
parameter
parserParser The content parser.
-
parameter
typesHash The available type conversions.
-
parameter
strictBoolean Whether unknown fields should produce validation errors.
-
returns
Model The frozen parameter model.
Implementation
def self.build(parser: Parser.default, types: TYPES, strict: true, &block)
return Builder.new(parser:, types:, strict:).build(&block)
end