-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make web_pipe compatible with dry-auto_inject
We remove the built-in resolution of plugs from a container and instead rely on the common mechanism provided by dry-auto_inject. As we're already allowing the injection of plugs and middlewares through keyword arguents given on `#initialize`, web_pipe remains compatible with the keyword arguments strategy of dry-auto_inject. We make sure that the order of inclusion of either web_pipe or dry-auto_inject is irrelevant for a correct behavior via dispatching any extra keyword arguments to `super`. ```ruby WebPipe.load_extensions(:params) class CreateUserApp include WebPipe include Deps[:create_user] plug :html, WebPipe::Plugs::ContentType.('text/html') plug :create private def create(conn) create_user.(conn.params) end end ```
- Loading branch information
1 parent
8129f12
commit 79f6c53
Showing
16 changed files
with
182 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
docs/recipes/injecting_dependencies_through_dry_auto_inject.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Injecting dependencies through dry-auto_inject | ||
|
||
`web_pipe` allows injecting [plugs](`../plugging_operations/injecting_operations.md`) and [middlewares](`../using_rack_middlewares/injecting_middlewares.md`) at initialization time. As they are given as keyword arguments to the `#initialize` method, `web_pipe` is only compatible with the [keyword argument strategy from dry-auto_inject](https://dry-rb.org/gems/dry-auto_inject/main/injection-strategies/#keyword-arguments-code-kwargs-code). This is useful in the case you need to use other collaborator from your plugs' definitions. | ||
|
||
```ruby | ||
WebPipe.load_extensions(:params) | ||
|
||
class CreateUserApp | ||
include WebPipe | ||
include Deps[:create_user] | ||
|
||
plug :html, WebPipe::Plugs::ContentType.('text/html') | ||
plug :create | ||
|
||
private | ||
|
||
def create(conn) | ||
create_user.(conn.params) | ||
end | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.