this repo has no description

Cleanup Credo warnings

hauleth.dev 1dae963c b588fbe1

verified
Changed files
+44 -8
config
lib
test
support
+2
config/dev.exs
···
"TQ20YLfpm8CWUZ0wvMVvXwKLjOdxb6//anr3iafpvW15LKlsoMez2OFUTifz0gxs",
watchers: []
+
config :esl_hn, refresh: :timer.seconds(5)
+
# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
+3 -3
config/runtime.exs
···
config :esl_hn, EslHnWeb.Endpoint, server: true
end
-
config :esl_hn,
-
refresh: CR.duration("ESL_HN_REFRESH", {:minutes, 5})
-
if config_env() == :prod do
+
config :esl_hn,
+
refresh: CR.duration("ESL_HN_REFRESH", {:minutes, 5})
+
secret_key_base =
System.get_env("SECRET_KEY_BASE") ||
raise """
+4
lib/esl_hn/cache.ex
···
defmodule EslHn.Cache do
+
@moduledoc """
+
Simple cache implementation using ETS tables
+
"""
+
use GenServer
def start_link(opts) do
+4
lib/esl_hn/hn.ex
···
defmodule EslHn.Hn do
+
@moduledoc """
+
Simple HTTP client for Hacker News API
+
"""
+
alias EslHn.Hn.Story
# TODO: Is there a way to limit amount of returned entries in query?
+6
lib/esl_hn/hn/story.ex
···
defmodule EslHn.Hn.Story do
+
@moduledoc """
+
Schema for describing Hacker News stories
+
+
Not all fields for it are currently used.
+
"""
+
use Ecto.Schema
import Ecto.Changeset
+3
lib/esl_hn/refresher.ex
···
defmodule EslHn.Refresher do
+
@moduledoc """
+
Module defining process that is responsible for refreshing cached data
+
"""
use GenServer
alias EslHn.Hn
+4
lib/esl_hn_web/api/controller.ex
···
defmodule EslHnWeb.API.Controller do
+
@moduledoc """
+
Controller for serving HN top stories cache
+
"""
+
use EslHnWeb, :controller
def index(conn, params) do
+4
lib/esl_hn_web/api/json.ex
···
defmodule EslHnWeb.API.JSON do
+
@moduledoc """
+
Simple JSON view into Hacker New stories
+
"""
+
def index(attrs) do
Enum.map(attrs.items, &one/1)
end
+10 -5
lib/esl_hn_web/api/socket.ex
···
defmodule EslHnWeb.API.Socket do
+
@moduledoc """
+
WebSocket API for serving top stories news
+
"""
+
@behaviour Phoenix.Socket.Transport
+
+
alias EslHnWeb.API.JSON, as: View
@impl true
def child_spec(_opts), do: :ignore
···
end
@impl true
-
def handle_in({message, opts}, state) do
-
dbg({message, opts})
-
+
def handle_in({_message, _opts}, state) do
+
# Ignore all incoming messages
{:ok, state}
end
@impl true
def handle_info(:do_init, state) do
stories = EslHn.all(1, 50)
-
data = EslHnWeb.API.JSON.index(%{items: stories})
+
data = View.index(%{items: stories})
{:push, {:text, JSON.encode_to_iodata!(data)}, state}
end
def handle_info({:new_stories, stories}, state) do
-
data = EslHnWeb.API.JSON.index(%{items: stories})
+
data = View.index(%{items: stories})
{:push, {:text, JSON.encode_to_iodata!(data)}, state}
end
+4
test/support/data.ex
···
defmodule EslHn.Test.Data do
+
@moduledoc """
+
Additional `StreamData` generators used during testing
+
"""
+
use ExUnitProperties
alias EslHn.Hn.Story