Shun.Rule.handle

You're seeing just the function handle, go back to Shun.Rule module for more information.
Link to this function

handle(pattern, handler)

View Source

Specs

handle(Shun.Rule.Target.t(), handle_fun()) :: t()

Generates a Dynamic rule for the given Target.

Expects a target conforming to Shun.Rule.Target.t/0.

The second argument must refer to a function, which accepts either an URI or an Address.

Example

You can use handle/2 to implement a Rule which will call your function at runtime if the value was matched.

defmodule MyApp.Shun do
  use Shun.Builder
  handle %URI{}, &custom_handle_uri/1

  def custom_handle_uri(uri) do
    cond do
      MyApp.Whitelist.allow_host?(uri.host) -> :accept
      true -> :reject
    end
  end
end

You can also use guards with handle/2:

defmodule MyApp.Shun do
  use Shun.Builder
  handle %URI{host: host} when host == "example.com", &custom_handle_uri/1

  
end