Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (25 sloc) 667 Bytes
defmodule StaticBlog.Repo do
use GenServer
def start_link do
GenServer.start_link(__MODULE__, :ok, [name: __MODULE__])
end
def list() do
GenServer.call(__MODULE__, {:list})
end
def get_by_slug(slug) do
GenServer.call(__MODULE__, {:get_by_slug, slug})
end
def init(:ok) do
posts = StaticBlog.Crawler.crawl
{:ok, posts}
end
def handle_call({:list}, _from, posts) do
{:reply, {:ok, posts}, posts}
end
def handle_call({:get_by_slug, slug}, _from, posts) do
case Enum.find(posts, fn(x) -> x.slug == slug end) do
nil -> {:reply, :not_found, posts}
post -> {:reply, {:ok, post}, posts}
end
end
end