ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - mruoss/pluggable: Elixir library to build Plug-like pipelines
Elixir library to build Plug-like pipelines. Contribute to mruoss/pluggable development by creating an account on GitHub.
Visit Site

GitHub - mruoss/pluggable: Elixir library to build Plug-like pipelines

GitHub - mruoss/pluggable: Elixir library to build Plug-like pipelines

Pluggable

Module Version Coverage Status Last Updated

Build Status CI Build Status Elixir

Hex Docs Total Download License

Pluggable helps to define Plug like pipelines but with arbitrary tokens. The library comes with almost exact copies of the module Plug and Plug.Builder. However, instead of passing around a %Plug.Conn{} struct, this library passes around a Token you define in your project.

Credits

Most of the code in this module was copied from the :plug library so credits go to the creators and maintainers of :plug.

Installation

The package can be installed by adding pluggable to your list of dependencies in mix.exs:

def deps do
  [
    {:pluggable, "~> 1.0"}
  ]
end

Usage

To use this library, you first have to define your token. Once that is done, use Pluggable.StepBuilder to build steps and pipelines.

Deriving Pluggable.Token

The easiest way to define a token is to create a module which derives Pluggable.Token and defines a struct which, among others defines the keys:

  • :halted - the boolean status on whether the pipeline was halted
  • :assigns - shared user data as a map

Example:

defmodule MyPipeline.Token do
  @derive Pluggable.Token
  defstruct [
    halted: false,
    assigns: %{},
    # other state
  ]
end

If the fields holding these two states are named differently, pass the fields as options to @derive:

defmodule MyPipeline.Token do
  @derive {Pluggable.Token, halted_key: :stopped, assigns_key: :shared_state}
  defstruct [
    stopped: false,
    shared_state: %{},
    # other state
  ]
end

Implementing Pluggable.Token

Pluggable.Token can be implemented. The following is the default implementation when deriving Pluggable.Token

  defmodule MyPipeline.Token do
    defstruct [
      halted: nil,
      assigns: %{},
      # other state
    ]
  end

  defimpl Pluggable.Token, for: MyPipeline.Token do
    def halted?(token), do: token.halted

    def halt(token), do: %{token | halted: true}

    def assign(%MyPipeline.Token{assigns: assigns} = token, key, value) when is_atom(key) do
      %{token | assigns: Map.put(assigns, key, value)}
    end
  end

Building Pipelines

Pluggable.StepBuilder works just like Plug.Builder. See the module documentation for instructions.

Pluggable.PipelineBuilder can be used to define and run multiple pipelines in the same module. See the module documentation for instructions.

Code Formatting

When using the Pluggable.StepBuilder, you might want to format the usage of the step macro without parens. To configure the formatter not to add parens, add this to your .formatter.exs:

# .formatter.exs
[
  import_deps: [:pluggable]
]

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory