Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 1.37 KB

README.md

File metadata and controls

63 lines (43 loc) · 1.37 KB

Fuel

Provides some useful modules that help with building consistent applications.

Ctx

Provides a context object similar to golangs context.Context that provides a way to thread data through a call-stack or even across process boundaries.

This is very useful for dependency injection especially when testing.

For example

setup do
  ctx = 
    Fuel.Ctx.new()
    |> Fuel.Ctx.with_impl(MyBehaviour, MyBehaviourMock)
  
  {:ok, %{ctx: ctx}}
end

test "test my thing", ctx do
  options = Fuel.Ctx.ctx_into(ctx.ctx, [])

  MyBehaviourMock
  |> expect(:some_call, fn _, _ -> :ok end)

  assert :ok == MyThing.call_a_function("yay", options)
end

In your code:

  def call_a_function(arg1, options) do
    with ctx <- Fuel.Ctx.ctx_from(options),
         my_behaviour <- Fuel.Ctx.fetch_impl(ctx, MyBehaviour) do
      
      my_behaviour.some_call(arg1, options)
    end
  end

Contexts are useful for more than just DI.

Installation

If available in Hex, the package can be installed by adding fuel to your list of dependencies in mix.exs:

def deps do
  [
    {:fuel, "~> 0.3.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/fuel.