fire_act v0.1.5 FireAct
Inspired by Plug, a helper module for defining action handlers with optional params validations via Ecto.Changeset.
Perfect for extracting logic outside the controller endpoints.
Example usage:
defmodule RegisterUser do
use FireAct.Handler
use FireAct.ChangesetParams, %{
age: :integer,
email: :string
}
def handle(action, permitted_params) do
%{email: _email, age: _age} = permitted_params
User.changeset(permitted_params)
|> Repo.update!()
end
def validate_params(_action, changeset) do
if "valid@example.com" == get_field(changeset, :email) do
changeset
else
changeset
|> add_error(:email, "only invalid@example.com")
end
end
end
{:ok, action} = FireAct.run(RegisterUser, %{
age: 1,
email: "valid@example.com"
})
Link to this section Summary
Link to this section Functions
Link to this function
action(conn, handler)
Link to this function
action(handler, params \\ %{}, assigns \\ %{})
Link to this function
plug_init_mode()
Link to this function
run(action)
Link to this function
run(action, opts)
Link to this function
run(handler, params, assigns)