abstract class UI::Controller

Overview

Abstract base class for native-target controllers that turn user actions into ActionResult values.

Defined in:

asset_pipeline/native_app.cr
asset_pipeline/native_controller.cr

Class Method Summary

Macro Summary

Instance Method Summary

Class Method Detail

def self._before_actions : Array(Proc(UI::Controller, UI::ScreenContext::Native, UI::ActionResult | Nil)) #

Abstract default — no callbacks registered.


[View source]

Macro Detail

macro before_action(method_name) #

Register a before_action. The method must accept a UI::ScreenContext::Native and return UI::ActionResult?.

before_action :require_authenticated

private def require_authenticated(context)
  return nil if context.session["user_email"]?
  navigate_to(:sign_in)
end

Implementation: emits a compile-time class method _before_action_<method_name>_proc that builds and returns the callback proc on demand. ._before_actions enumerates those methods to assemble the list. Compile-time method emission is gap-safe; the prior @@_before_actions << ... class-body side effect was not.


[View source]

Instance Method Detail

def dispatch_action(name : Symbol, context : UI::ScreenContext::Native) : UI::ActionResult #

Subclasses override this method with a case dispatch over the action names they implement. The default implementation raises UnknownActionError with guidance pointing the author at the override path.


[View source]