Compare commits
No commits in common. "0425add7f765aba0d36e76bc8aa6f2931a4d8c9d" and "eb9bf1980a54dc07795b2ed61bd8f053b9e67d24" have entirely different histories.
0425add7f7
...
eb9bf1980a
|
|
@ -1,15 +0,0 @@
|
|||
defmodule Aife.Application do
|
||||
@moduledoc false
|
||||
|
||||
use Application
|
||||
|
||||
def start(_, _) do
|
||||
children = [
|
||||
Aife.Drone.Supervisor
|
||||
]
|
||||
|
||||
opts = [strategy: :one_for_one, name: Aife.Supervisor]
|
||||
|
||||
Supervisor.start_link(children, opts)
|
||||
end
|
||||
end
|
||||
|
|
@ -16,12 +16,6 @@ defmodule Aife.Drone do
|
|||
"""
|
||||
@moduledoc since: "0.1.0"
|
||||
|
||||
alias Aife.Drone
|
||||
|
||||
use GenServer
|
||||
|
||||
defstruct enabled?: false, human: %{traits: %{}}, drone: %{traits: %{}}, values: %{}
|
||||
|
||||
@doc """
|
||||
Sends a command to a drone.
|
||||
|
||||
|
|
@ -29,7 +23,6 @@ defmodule Aife.Drone do
|
|||
"""
|
||||
@doc since: "0.1.0"
|
||||
def command(drone, cmd) do
|
||||
GenServer.cast(drone, {:command, cmd})
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -41,7 +34,6 @@ defmodule Aife.Drone do
|
|||
"""
|
||||
@doc since: "0.1.0"
|
||||
def enable(drone) do
|
||||
GenServer.cast(drone, :enable)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -51,7 +43,6 @@ defmodule Aife.Drone do
|
|||
"""
|
||||
@doc since: "0.1.0"
|
||||
def disable(drone) do
|
||||
GenServer.cast(drone, :disable)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -59,7 +50,6 @@ defmodule Aife.Drone do
|
|||
"""
|
||||
@doc since: "0.1.0"
|
||||
def traits(drone) do
|
||||
GenServer.call(drone, :traits)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -79,7 +69,6 @@ defmodule Aife.Drone do
|
|||
"""
|
||||
@doc since: "0.1.0"
|
||||
def alter_traits(drone, form \\ :current, values \\ []) do
|
||||
GenServer.cast(drone, {:alter, form, values})
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -93,11 +82,10 @@ defmodule Aife.Drone do
|
|||
Aife.Drone.get_values(drone, :fetishes)
|
||||
#=> [fetishes: [:maid, :latex, :hypnosis]]
|
||||
Aife.Drone.insert_value(drone, :fetishes, :haigure)
|
||||
#=> [fetishes: [:maid, :latex, :haigure, :hypnosis]]
|
||||
#=> {:ok, [fetishes: [:maid, :latex, :haigure, :hypnosis]]}
|
||||
"""
|
||||
@doc since: "0.1.0"
|
||||
def insert_value(drone, key, value) do
|
||||
GenServer.call(drone, {:insert_value, key, value})
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -113,13 +101,12 @@ defmodule Aife.Drone do
|
|||
Aife.Drone.get_values(drone, :fetishes)
|
||||
#=> [fetishes: [:maid, :latex, :haigure, :hypnosis]]
|
||||
Aife.Drone.remove_value(drone, :fetishes, :haigure)
|
||||
#=> [fetishes: [:maid, :latex, :hypnosis]]
|
||||
#=> {:ok, [fetishes: [:maid, :latex, :hypnosis]]}
|
||||
Aife.Drone.remove_value(drone, :fetishes, :haigure)
|
||||
#=> [fetishes: [:maid, :latex, :hypnosis]]
|
||||
#=> {:ok, [fetishes: [:maid, :latex, :hypnosis]]}
|
||||
"""
|
||||
@doc since: "0.1.0"
|
||||
def remove_value(drone, key, value) do
|
||||
GenServer.call(drone, {:remove_value, key, value})
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -129,7 +116,6 @@ defmodule Aife.Drone do
|
|||
"""
|
||||
@doc since: "0.1.0"
|
||||
def say(drone, text) do
|
||||
GenServer.cast(drone, {:say, text})
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -146,45 +132,5 @@ defmodule Aife.Drone do
|
|||
"""
|
||||
@doc since: "0.1.0"
|
||||
def think(drone, thought) do
|
||||
GenServer.cast(drone, {:think, thought})
|
||||
end
|
||||
|
||||
## GenServer calls.
|
||||
|
||||
def start_link() do
|
||||
GenServer.start_link(__MODULE__, [])
|
||||
end
|
||||
|
||||
@impl GenServer
|
||||
def init(_) do
|
||||
{:ok, %Drone{}}
|
||||
end
|
||||
|
||||
@impl GenServer
|
||||
def handle_call(:traits, _from, state) do
|
||||
form =
|
||||
case state.enabled? do
|
||||
true -> :drone
|
||||
false -> :human
|
||||
end
|
||||
|
||||
{:reply, state[form].traits, state}
|
||||
end
|
||||
|
||||
def handle_call({:insert_value, key, value}, _from, state) do
|
||||
# TODO
|
||||
{:reply, state, state}
|
||||
end
|
||||
|
||||
def handle_call({:remove_value, key, value}, _from, state) do
|
||||
# TODO
|
||||
{:reply, state, state}
|
||||
end
|
||||
|
||||
@impl GenServer
|
||||
def handle_cast({:command, _cmd}, state), do: {:noreply, state}
|
||||
def handle_cast(:disable, state), do: {:noreply, %{state | enabled?: false}}
|
||||
def handle_cast(:enable, state), do: {:noreply, %{state | enabled?: true}}
|
||||
def handle_cast({:say, _text}, state), do: {:noreply, state}
|
||||
def handle_cast({:think, _thought}, state), do: {:noreply, state}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
defmodule Aife.Drone.DynamicSupervisor do
|
||||
use DynamicSupervisor
|
||||
|
||||
def start_link(_) do
|
||||
DynamicSupervisor.start_link(__MODULE__, nil, name: __MODULE__)
|
||||
end
|
||||
|
||||
@impl DynamicSupervisor
|
||||
def init(_init_arg) do
|
||||
DynamicSupervisor.init(strategy: :one_for_one)
|
||||
end
|
||||
end
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
defmodule Aife.Drone.Supervisor do
|
||||
use Supervisor
|
||||
|
||||
def start_link(_) do
|
||||
Supervisor.start_link(__MODULE__, [])
|
||||
end
|
||||
|
||||
def init(_) do
|
||||
children = [
|
||||
{Registry, name: Aife.Drone.Registry, keys: :unique},
|
||||
{DynamicSupervisor, name: Aife.Drone.DynamicSupervisor, strategy: :one_for_one}
|
||||
]
|
||||
|
||||
Supervisor.init(children, strategy: :one_for_one)
|
||||
end
|
||||
end
|
||||
3
mix.exs
3
mix.exs
|
|
@ -26,8 +26,7 @@ defmodule Aife.MixProject do
|
|||
# Run "mix help compile.app" to learn about applications.
|
||||
def application do
|
||||
[
|
||||
extra_applications: [:logger],
|
||||
mod: {Aife.Application, []}
|
||||
extra_applications: [:logger]
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
defmodule Aife.DroneTest do
|
||||
use ExUnit.Case
|
||||
doctest Aife.Drone
|
||||
end
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
defmodule AifeTest do
|
||||
use ExUnit.Case
|
||||
doctest Aife
|
||||
|
||||
test "greets the world" do
|
||||
assert Aife.hello() == :world
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue