-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider following plug conventions and implementing pipeline/pipe macros #30
Comments
Hi @sitch ! First of all, thanks a lot for sharing the idea. We think it's amazing and it's definitively the way we should focus the next major release of Ravenx. This change alongside with #28 to reduce unnecessary dependencies are two improvements that can make this library a better one. If you feel comfortable to participate in the development, you are more than welcome. Otherwise don't worry, the fact of giving us the idea is more than enough. Thanks! ❤️ |
Thanks :) Take a look at https://github.com/appunite/piper |
Thinking about the approach we can take on this, these are the ideas that came up to my mind (are a version of what was firstly exposed by @sitch) defmodule MyApp.Notifications.NewEvent do
use Ravenx.Pipeline
@slack_config [
view: MyApp.NotificationsView,
template: "slack_event.text",
channel: "events",
async: true
]
@email_config [
view: MyApp.NotificationsView,
template: "email_event.text",
subject: &("Welcome #{&1.assigns.user.name}")
]
pipe MyApp.SlackStrategy, @slack_config
pipe MyApp.EmailStrategy, @email_config
def init do
[]
end
def call(instance, _opts, payload) do
user = MyApp.Repo.preload(payload, :friends)
instance.assign(:user, user)
end
end defmodule MyApp.SlackStrategy do
use Ravenx.Pipe
use Ravenx.Strategies.Slack # `channel/2`, `render_title/2`, `render_body/3`, `send/1`
def init(opts) do
options
end
def call(instance, opts) do
instance
|> channel(opts[:channel])
|> render_title(opts[:title])
|> render_body(opts[:view], opts[:template])
|> deliver
end
end The app's strategies are intended to be a custom configuration (and use) of the integration itself, specifying how a (for example, Slack) integration is built in the app itself. And the The Also, the |
Consider following plug conventions:
init/1
andcall/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.
The text was updated successfully, but these errors were encountered: