Marten::Schema
Inherits Marten::Template::Object / Marten::Template::CanDefineTemplateAttributes / Marten::Core::Validation::Callbacks / Marten::Core::Validation / Reference / Object
Abstract base schema class.
Schemas allow to define how a data set should be validated and what fields are expected. Schemas can be used to validate query parameters, forms data, files, or JSON objects.
Constructors
Class methods
Instance methods
Returns the bound field associated with the passed field name or raises if the field is not present.
Returns the bound field associated with the passed field name or nil if the field is not present.
Allows to read the value of a specific field.
This methods returns the value of the field corresponding to field_name. If the passed field_name doesn't
match any existing field, a Marten::Schema::Errors::UnknownField exception is raised.
Macros
Allows to define a schema field.
At least two positional arguments are required when defining schema fields: a field identifier and a field type. Depending on the considered field types, additional keyword arguments can be used in order to customize on the field behaves and how it handles validations:
class MySchema < Marten::Schema
field :my_field, :string, required: true, max_size: 128
end