Presently, the only way to extend the logic involved when processing valid/invalid schemas as part of handlers (subclasses of Marten::Handlers::Schema) is to override the #process_valid_schema and #process_invalid_schema.
For example:
class MyFormHandler < Marten::Handlers::Schema
schema MySchema
template_name "app/my_form.html"
success_route_name "home"
def process_valid_schema
# This method is called when the schema is valid.
# You can decide to do something with the validated data...
super
end
def process_invalid_schema
# This method is called when the schema is invalid.
super
end
end
This works fine, but overriding methods from the Marten::Handlers::Schema base class is not ideal. Being able to register methods to execute upon processing valid/invalid schemas would be preferable.
In this light, let's introduce the ability to define new kinds of callbacks as part of schema handlers (subclasses of Marten::Handlers::Schema):
before_schema_validation - callbacks executed before the schema instance is actually validated
after_schema_validation - callbacks executed after the schema instance validation has been executed
after_successful_schema_validation - callbacks executed after the schema validation succeeded
after_failed_schema_validation - callbacks executed after the schema validation failed
If one of these callbacks returns an HTTP response object (instance of Marten::HTTP::Response), then the obtained response should bypass the rest of the schema handler implementation and be returned directly (like this is the case for standard handler callbacks).
Description
Presently, the only way to extend the logic involved when processing valid/invalid schemas as part of handlers (subclasses of
Marten::Handlers::Schema
) is to override the#process_valid_schema
and#process_invalid_schema
.For example:
This works fine, but overriding methods from the
Marten::Handlers::Schema
base class is not ideal. Being able to register methods to execute upon processing valid/invalid schemas would be preferable.In this light, let's introduce the ability to define new kinds of callbacks as part of schema handlers (subclasses of
Marten::Handlers::Schema
):before_schema_validation
- callbacks executed before the schema instance is actually validatedafter_schema_validation
- callbacks executed after the schema instance validation has been executedafter_successful_schema_validation
- callbacks executed after the schema validation succeededafter_failed_schema_validation
- callbacks executed after the schema validation failedIf one of these callbacks returns an HTTP response object (instance of
Marten::HTTP::Response
), then the obtained response should bypass the rest of the schema handler implementation and be returned directly (like this is the case for standard handler callbacks).