Consider following plug conventions:init/1 and call/2. Also would be more natural to have pipeline/pipe macros. I.e.:
defmodule MyApp.MyEvent do
use Ravenx.Pipeline
use MyApp.PhoenixSlackPipe, view: MyApp.SlackView, template: "new_slack_event.text"
use MyApp.PhoenixEmailPipe, view: MyApp.EmailView, template: "new_email_event.text"
pipe :slack, channel: "events", async: true
pipe :email, contact: & &1.assigns.user.email, subject: &"Welcome #{&1.assigns.user.name}"
def call(pipeline, _opts, payload) do
user = MyApp.Repo.preload(payload, :friends)
pipeline.assign(:user, user)
end
end
and for a pipe:
defmodule MyApp.PhoenixSlackPipe do
use Ravenx.Pipe
use MyApp.PhoenixSlack # `channel/2`, `render_title/2`, `render_body/3`, `send/1`
def init(_pipeline, options) do
options
end
def call(pipeline, options) do
pipeline
|> channel(options[:channel])
|> render_title(options[:title])
|> render_body(options[:view], options[:template]) # renders with `pipeline.assigns`
|> send
end
end
This type of design would make it so you don't have to load strategies in your config (which doesn't seem necessary), instead you just use them in your Pipe files.
Consider following plug conventions:
init/1andcall/2. Also would be more natural to have pipeline/pipe macros. I.e.:and for a pipe:
This type of design would make it so you don't have to load strategies in your config (which doesn't seem necessary), instead you just use them in your Pipe files.