Repository navigation
Pipeline
Laravex.Pipeline is a passable pipeline that sends a value through a sequence of pipes and returns the result to a final destination callback. It mirrors the Laravel Illuminate\Pipeline\Pipeline interface.
alias Laravex.Pipeline
result =
Pipeline.send(passable)
|> Pipeline.through([PipeA, PipeB, PipeC])
|> Pipeline.then(fn value -> value end)send/1 accepts any value. through/2 accepts a list of pipes. then/2 runs the pipeline and passes the result to the destination function.
A pipe can be:
| Form | Behaviour |
|---|---|
fn value -> new_value end |
1-arity anonymous function |
MyModule |
MyModule.handle(value) is called (default method) |
{MyModule, :my_fun} |
MyModule.my_fun(value) is called |
defmodule App.Pipes.TrimInput do
def handle(value) when is_binary(value), do: String.trim(value)
def handle(value), do: value
end
defmodule App.Pipes.Uppercase do
def handle(value) when is_binary(value), do: String.upcase(value)
def handle(value), do: value
end
result =
Pipeline.send(" hello world ")
|> Pipeline.through([App.Pipes.TrimInput, App.Pipes.Uppercase])
|> Pipeline.then(fn value -> value end)
# => "HELLO WORLD"By default, Laravex.Pipeline calls the :handle method on module pipes. Use via/2 to change the method name:
Pipeline.send(request)
|> Pipeline.through([CheckAuth, LogRequest])
|> Pipeline.via(:process)
|> Pipeline.then(fn req -> req end)Each module pipe will now be called as Module.process(value) instead of Module.handle(value).
A pipe may return {:halt, value} to stop the pipeline immediately. The halted value is still passed to the then/2 destination:
defmodule App.Pipes.CheckMaintenance do
def handle(request) do
if Laravex.Foundation.Maintenance.active?() do
{:halt, Laravex.Http.Response.html("Down for maintenance", 503)}
else
request
end
end
end
response =
Pipeline.send(request)
|> Pipeline.through([App.Pipes.CheckMaintenance, App.Pipes.Authenticate])
|> Pipeline.then(fn req -> handle_request(req) end)If CheckMaintenance returns {:halt, response}, Authenticate is not called and the destination receives the halted value directly.
through/2 accumulates pipes, so you can compose partial pipelines:
base =
Pipeline.send(input)
|> Pipeline.through([PipeA, PipeB])
result =
base
|> Pipeline.through([PipeC, PipeD])
|> Pipeline.then(fn value -> value end)- Middleware — HTTP middleware is a pipeline under the hood
- Events — Listeners form a similar pipe-and-dispatch pattern
Laravex — Laravel-faithful application skeleton & runtime for Elixir.
GitHub
·
Docs
·
Limitations
·
Laravel Docs
Not affiliated with Laravel LLC or the Elixir core team. Built to feel like Laravel on the BEAM.
- Home
- Installation
- Configuration
- Directory-Structure
- Request-Lifecycle
- Service-Container
- Service-Providers
- Deployment
- Routing
- Middleware
- CSRF-Protection
- Controllers
- Requests
- Responses
- Views
- Blade-Templates
- Asset-Bundling
- Session
- Validation
- Error-Handling
- Logging
- Artisan-Console
- Broadcasting
- Cache
- Collections
- Events
- File-Storage
- Helpers
- HTTP-Client
- Localization
- Notifications
- Pipeline
- Queues
- Rate-Limiting
- Strings
- Task-Scheduling