Compare commits

..

No commits in common. "0425add7f765aba0d36e76bc8aa6f2931a4d8c9d" and "eb9bf1980a54dc07795b2ed61bd8f053b9e67d24" have entirely different histories.

7 changed files with 8 additions and 106 deletions

View File

@ -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

View File

@ -16,12 +16,6 @@ defmodule Aife.Drone do
""" """
@moduledoc since: "0.1.0" @moduledoc since: "0.1.0"
alias Aife.Drone
use GenServer
defstruct enabled?: false, human: %{traits: %{}}, drone: %{traits: %{}}, values: %{}
@doc """ @doc """
Sends a command to a drone. Sends a command to a drone.
@ -29,7 +23,6 @@ defmodule Aife.Drone do
""" """
@doc since: "0.1.0" @doc since: "0.1.0"
def command(drone, cmd) do def command(drone, cmd) do
GenServer.cast(drone, {:command, cmd})
end end
@doc """ @doc """
@ -41,7 +34,6 @@ defmodule Aife.Drone do
""" """
@doc since: "0.1.0" @doc since: "0.1.0"
def enable(drone) do def enable(drone) do
GenServer.cast(drone, :enable)
end end
@doc """ @doc """
@ -51,7 +43,6 @@ defmodule Aife.Drone do
""" """
@doc since: "0.1.0" @doc since: "0.1.0"
def disable(drone) do def disable(drone) do
GenServer.cast(drone, :disable)
end end
@doc """ @doc """
@ -59,7 +50,6 @@ defmodule Aife.Drone do
""" """
@doc since: "0.1.0" @doc since: "0.1.0"
def traits(drone) do def traits(drone) do
GenServer.call(drone, :traits)
end end
@doc """ @doc """
@ -79,7 +69,6 @@ defmodule Aife.Drone do
""" """
@doc since: "0.1.0" @doc since: "0.1.0"
def alter_traits(drone, form \\ :current, values \\ []) do def alter_traits(drone, form \\ :current, values \\ []) do
GenServer.cast(drone, {:alter, form, values})
end end
@doc """ @doc """
@ -93,11 +82,10 @@ defmodule Aife.Drone do
Aife.Drone.get_values(drone, :fetishes) Aife.Drone.get_values(drone, :fetishes)
#=> [fetishes: [:maid, :latex, :hypnosis]] #=> [fetishes: [:maid, :latex, :hypnosis]]
Aife.Drone.insert_value(drone, :fetishes, :haigure) Aife.Drone.insert_value(drone, :fetishes, :haigure)
#=> [fetishes: [:maid, :latex, :haigure, :hypnosis]] #=> {:ok, [fetishes: [:maid, :latex, :haigure, :hypnosis]]}
""" """
@doc since: "0.1.0" @doc since: "0.1.0"
def insert_value(drone, key, value) do def insert_value(drone, key, value) do
GenServer.call(drone, {:insert_value, key, value})
end end
@doc """ @doc """
@ -113,13 +101,12 @@ defmodule Aife.Drone do
Aife.Drone.get_values(drone, :fetishes) Aife.Drone.get_values(drone, :fetishes)
#=> [fetishes: [:maid, :latex, :haigure, :hypnosis]] #=> [fetishes: [:maid, :latex, :haigure, :hypnosis]]
Aife.Drone.remove_value(drone, :fetishes, :haigure) Aife.Drone.remove_value(drone, :fetishes, :haigure)
#=> [fetishes: [:maid, :latex, :hypnosis]] #=> {:ok, [fetishes: [:maid, :latex, :hypnosis]]}
Aife.Drone.remove_value(drone, :fetishes, :haigure) Aife.Drone.remove_value(drone, :fetishes, :haigure)
#=> [fetishes: [:maid, :latex, :hypnosis]] #=> {:ok, [fetishes: [:maid, :latex, :hypnosis]]}
""" """
@doc since: "0.1.0" @doc since: "0.1.0"
def remove_value(drone, key, value) do def remove_value(drone, key, value) do
GenServer.call(drone, {:remove_value, key, value})
end end
@doc """ @doc """
@ -129,7 +116,6 @@ defmodule Aife.Drone do
""" """
@doc since: "0.1.0" @doc since: "0.1.0"
def say(drone, text) do def say(drone, text) do
GenServer.cast(drone, {:say, text})
end end
@doc """ @doc """
@ -146,45 +132,5 @@ defmodule Aife.Drone do
""" """
@doc since: "0.1.0" @doc since: "0.1.0"
def think(drone, thought) do def think(drone, thought) do
GenServer.cast(drone, {:think, thought})
end 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 end

View File

@ -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

View File

@ -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

View File

@ -26,8 +26,7 @@ defmodule Aife.MixProject do
# Run "mix help compile.app" to learn about applications. # Run "mix help compile.app" to learn about applications.
def application do def application do
[ [
extra_applications: [:logger], extra_applications: [:logger]
mod: {Aife.Application, []}
] ]
end end

View File

@ -1,4 +0,0 @@
defmodule Aife.DroneTest do
use ExUnit.Case
doctest Aife.Drone
end

View File

@ -1,4 +1,8 @@
defmodule AifeTest do defmodule AifeTest do
use ExUnit.Case use ExUnit.Case
doctest Aife doctest Aife
test "greets the world" do
assert Aife.hello() == :world
end
end end