Skip to content

Commit

Permalink
Merge pull request #65 from mattr-/alice-initialization-require-struct
Browse files Browse the repository at this point in the history
Make application initialization take a struct
  • Loading branch information
adamzaninovich authored Jun 14, 2016
2 parents ae25e35 + 612a66f commit bff770b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,15 @@ handler. We recommend putting them in `lib/alice/handlers/`.)
def application do
[ applications: [:alice],
mod: {
Alice, [
Alice.Handlers.Random,
Alice.Handlers.AgainstHumanity,
Alice.Handlers.GoogleImages
] } ]
Alice, %{
handlers: [
Alice.Handlers.Random,
Alice.Handlers.AgainstHumanity,
Alice.Handlers.GoogleImages
]
}
}
]
end
```

Expand Down
12 changes: 8 additions & 4 deletions lib/alice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ defmodule Alice do
List of Alice route handlers to register upon startup
"""
def handlers(extras) do
[Alice.Earmuffs,
Alice.Handlers.Help,
Alice.Handlers.Utils
] ++ extras
case Map.fetch(extras, :handlers) do
{:ok, additional_handlers} -> default_handlers ++ additional_handlers
_ -> default_handlers
end
end

@doc """
Expand Down Expand Up @@ -42,4 +42,8 @@ defmodule Alice do
_other -> []
end
end

defp default_handlers do
[Alice.Earmuffs, Alice.Handlers.Help, Alice.Handlers.Utils ]
end
end
14 changes: 14 additions & 0 deletions test/alice_test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
defmodule AliceTest do
use ExUnit.Case, async: true
doctest Alice

alias Alice.Handlers.TestHandler

test "contains a default set of handlers" do
assert [Alice.Earmuffs, Alice.Handlers.Help, Alice.Handlers.Utils] == Alice.handlers(%{})
end

test "properly adds handlers to the list when they're provided" do
assert [Alice.Earmuffs,
Alice.Handlers.Help,
Alice.Handlers.Utils,
Alice.Handlers.TestHandler] ==
Alice.handlers(%{handlers: [TestHandler]})
end
end

0 comments on commit bff770b

Please sign in to comment.