Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Elixir 1.6 #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
language: elixir
elixir:
- 1.6.6
otp_release:
- 20.0
env:
- MIX_ENV=test
script: mix test
sudo: false
6 changes: 2 additions & 4 deletions lib/consul/handler/behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
#

defmodule Consul.Handler.Behaviour do
use Behaviour

defcallback handle(result :: Consul.Response.t)
@callback handle(result :: Consul.Response.t) :: Consul.Endpoint.response

defmacro __using__(_) do
quote do
@behaviour unquote(__MODULE__)

@spec handle(Consul.Response.t) :: Consule.Endpoint.response
@spec handle(Consul.Response.t) :: Consul.Endpoint.response
def handle(%{status_code: 200} = response) do
{:ok, response}
end
Expand Down
2 changes: 1 addition & 1 deletion lib/consul/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Consul.Request do
<<"https://"::utf8, _::binary>> ->
url
_ ->
Path.join("http://#{host}:#{port}/v1", url)
Path.join("http://#{host()}:#{port()}/v1", url)
end
end

Expand Down
9 changes: 4 additions & 5 deletions lib/consul/watch/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ defmodule Consul.Watch.Event do
@wait "10m"
@retry_ms 30 * 1000

@spec start_link(binary, GenEvent.handler | {GenEvent.handler, list}) :: GenServer.on_start
def start_link(name, handlers \\ []) do
GenServer.start_link(__MODULE__, [name, handlers])
end
Expand All @@ -24,13 +23,13 @@ defmodule Consul.Watch.Event do
#

def init([name, handlers]) do
{:ok, em} = GenEvent.start_link(handlers)
{:ok, em} = :gen_event.start_link(handlers)

Enum.each handlers, fn
{handler, args} ->
:ok = GenEvent.add_handler(em, handler, args)
:ok = :gen_event.add_handler(em, handler, args)
handler ->
:ok = GenEvent.add_handler(em, handler, [])
:ok = :gen_event.add_handler(em, handler, [])
end

{:ok, %{name: name, em: em, index: nil, l_time: nil}, 0}
Expand All @@ -39,7 +38,7 @@ defmodule Consul.Watch.Event do
def handle_info(:timeout, %{name: name, index: index, em: em, l_time: l_time} = state) do
case Event.list(wait: @wait, index: index) do
{:ok, response} ->
events = Event.from_response(response) |> Enum.filter &(&1.name == name)
events = Event.from_response(response) |> Enum.filter(&(&1.name == name))
new_l_time = Event.last_time(events)
notify_events(events, em, index, l_time)
{:noreply, %{state | index: consul_index(response), l_time: new_l_time}, 0}
Expand Down
8 changes: 3 additions & 5 deletions lib/consul/watch/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#

defmodule Consul.Watch.Handler do
use Behaviour

@type on_return :: {:ok, term} | :remove_handler

Expand All @@ -15,12 +14,12 @@ defmodule Consul.Watch.Handler do

See: http://www.consul.io/docs/agent/http.html#event
"""
defcallback handle_consul_events(events :: [Consul.Event.t], list) :: on_return
@callback handle_consul_events([Consul.Event.t], any) :: on_return

defmacro __using__(_) do
quote do
@behaviour Consul.Watch.Handler
use GenEvent
@behaviour :gen_event

@doc false
def handle_event({:consul_events, events}, state) do
Expand All @@ -43,9 +42,8 @@ defmodule Consul.Watch.Handler do
@doc """
Notifies handlers attached a Watch's event manager of Consul Events.
"""
@spec notify_events(GenEvent.manager, [Consul.Event.t]) :: :ok
def notify_events(_, []), do: :ok
def notify_events(manager, events) when is_pid(manager) and is_list(events) do
GenEvent.ack_notify(manager, {:consul_events, events})
:gen_event.notify(manager, {:consul_events, events})
end
end
8 changes: 4 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Consul.Mixfile do
[
app: :consul,
version: "1.1.0",
elixir: "~> 1.0",
elixir: "~> 1.6",
deps: deps(),
package: package(),
description: description()
Expand All @@ -28,9 +28,9 @@ defmodule Consul.Mixfile do

defp deps do
[
{:exjsx, "~> 3.0"},
{:httpoison, "~> 0.11.0"},
{:ex_doc, "~> 0.14", only: :dev}
{:exjsx, "~> 4.0.0"},
{:httpoison, "~> 1.2.0"},
{:ex_doc, "~> 0.19.1", only: :dev}
]
end

Expand Down