suitepad-gmbh / pipette

Flow-Based Programming framework for Elixir
MIT License
21 stars 3 forks source link

[FEATURE] Support custom handler #18

Closed spieker closed 6 years ago

spieker commented 6 years ago

This enables the user to switch from the default Pipette.Handler to a custom Handler. A custom handler could do some pre- or post-processing to the IP or the given handler definition.

Example:

defmodule MapProtocolHandler do
  alias Pipette.IP

  # Run the handler and assigning the result to the key specified in the
  # arguments
  def handle(handler, %IP{value: %{} = map} = ip) do
    %IP{route: route, value: new_value} = new_ip = Pipette.Handler.handle(handler, ip)
    result_value = compose_result(map, new_value)
    IP.update(new_ip, {route, result_value})
  end

  defp compose_result(%{} = map, new_value, handler) do
    args = get_args(handler)
    case args[:RESULT_KEY] do
      key -> Map.put(map, key, new_value)
      _ -> new_value
    end
  end
end
config :pipette, handler: MapProtocolHandler
spieker commented 6 years ago

@Overbryd Any thoughts on this solution?

Overbryd commented 6 years ago

Yep, I think we need one document in guides/configuration.md that explains the available configuration options.

In general, I think this solution will aid certain implementations. However, I think it might be nice to be able to override this per recipe rather than for a whole application.

On 20. Jul 2018, at 15:38, Hildebrando Rueda notifications@github.com wrote:

@theharq approved this pull request.

LGTM, maybe adding a reference in the README that this configuration is possible will be nice.

— You are receiving this because your review was requested. Reply to this email directly, view it on GitHub https://github.com/suitepad-gmbh/pipette/pull/18#pullrequestreview-139084204, or mute the thread https://github.com/notifications/unsubscribe-auth/AABSd8GQVu0U858SZI7yGh6o1ywhPjolks5uIetigaJpZM4VX4ck.

spieker commented 6 years ago

I think we can add a handler configuration on recipe level as another feature.