Skip to content

Instant Elixir behaviours, creates callbacks from specs.

License

Notifications You must be signed in to change notification settings

koudelka/behaves_like

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BehavesLike

Build Status Hex pm

Turns a module's specs into callbacks.

Lets you state that a module behaves like another, without writing behaviour callbacks.

Uses a macro for 1.7, until elixir-lang/elixir#8085 is fixed.

For example:

defmodule API do
  use BehavesLike
  import BehavesLike, only: [spec_and_callback: 1]

  spec_and_callback get(binary()) :: {:ok, any()} | {:error, any()}
  def get(id) do
    Backend.get(id)
  end
end

defmodule Backend do
  @behaviour API

  @impl true
  def get(id) do
    database().get(id)
  end
end

Installation

From Hex:

def deps do
  [
    {:behaves_like, "~> 0.5.0"}
  ]
end

Usage

Import the required macro, then declare your specs with spec_and_callback/1, as in the example above.

About

Instant Elixir behaviours, creates callbacks from specs.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages