https://github.com/marcelotto/behaviour_reflection
Get all modules implementing an Elixir behaviour
https://github.com/marcelotto/behaviour_reflection
elixir reflection
Last synced: 4 months ago
JSON representation
Get all modules implementing an Elixir behaviour
- Host: GitHub
- URL: https://github.com/marcelotto/behaviour_reflection
- Owner: marcelotto
- License: mit
- Created: 2020-05-12T00:26:01.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-12T09:26:57.000Z (over 5 years ago)
- Last Synced: 2025-07-19T09:29:24.269Z (6 months ago)
- Topics: elixir, reflection
- Language: Elixir
- Homepage: https://hex.pm/packages/behaviour_reflection
- Size: 11.7 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Behaviour.Reflection
[](https://travis-ci.org/marcelotto/behaviour_reflection)
[](https://hex.pm/packages/behaviour_reflection)
Get all modules implementing an Elixir behaviour.
See [this article](https://medium.com/@MarcelOttoDE/the-walled-gardens-within-elixir-d0507a568015) for an analysis of the problem, the circumstances for when to use this library, how it works and its caveats.
## Installation
The Hex package can be installed as usual, by adding `behaviour_reflection` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:behaviour_reflection, "~> 0.1"}
]
end
```
## Usage
Let's say you have a behaviour and a number of modules implementing it:
```elixir
defmodule MyBehaviour do
@callback fun :: String.t
end
defmodule Foo do
@behaviour MyBehaviour
def fun(), do: "foo"
end
defmodule Bar do
@behaviour MyBehaviour
def fun(), do: "bar"
end
```
At runtime you can retrieve all modules implementing the behaviour like this:
```elixir
iex> Behaviour.Reflection.impls(MyBehaviour)
[Foo, Bar]
```
Documentation can be found at [https://hexdocs.pm/behaviour_reflection](https://hexdocs.pm/behaviour_reflection).