Skip to content
/ fuel Public

Useful functionality for consistent applications

License

Notifications You must be signed in to change notification settings

hassox/fuel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Useful functionality for consistent applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages