https://github.com/koudelka/behaves_like
Instant Elixir behaviours, creates callbacks from specs.
https://github.com/koudelka/behaves_like
behaviour elixir
Last synced: about 1 year ago
JSON representation
Instant Elixir behaviours, creates callbacks from specs.
- Host: GitHub
- URL: https://github.com/koudelka/behaves_like
- Owner: koudelka
- License: mit
- Created: 2018-06-01T20:34:20.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-06T21:52:39.000Z (over 7 years ago)
- Last Synced: 2025-04-11T11:40:59.594Z (about 1 year ago)
- Topics: behaviour, elixir
- Language: Elixir
- Homepage:
- Size: 20.5 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BehavesLike
[](https://travis-ci.org/koudelka/behaves_like)
[](https://hex.pm/packages/behaves_like)
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 https://github.com/elixir-lang/elixir/issues/8085 is fixed.
For example:
```elixir
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:
```elixir
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.