Skip to content

Commit 46c1ce4

Browse files
committed
chore(ex:1.4): update per elixir 1.4 warning deprecations
1 parent 3965bf7 commit 46c1ce4

27 files changed

+128
-127
lines changed

lib/rethinkdb/connection.ex

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ defmodule RethinkDB.Connection do
5151
defmacro __using__(_opts) do
5252
quote location: :keep do
5353
def start_link(opts \\ []) do
54-
if Dict.has_key?(opts, :name) && opts[:name] != __MODULE__ do
54+
if Keyword.has_key?(opts, :name) && opts[:name] != __MODULE__ do
5555
# The whole point of this macro is to provide an implicit process
5656
# name, so subverting it is considered an error.
5757
raise ArgumentError.exception(
5858
"Process name #{inspect opts[:name]} conflicts with implicit name #{inspect __MODULE__} provided by `use RethinkDB.Connection`"
5959
)
6060
end
61-
RethinkDB.Connection.start_link(Dict.put_new(opts, :name, __MODULE__))
61+
RethinkDB.Connection.start_link(Keyword.put_new(opts, :name, __MODULE__))
6262
end
6363

6464
def run(query, opts \\ []) do
@@ -98,12 +98,13 @@ defmodule RethinkDB.Connection do
9898
* `profile` - whether or not to return a profile of the query’s execution (default: false).
9999
"""
100100
def run(query, conn, opts \\ []) do
101-
timeout = Dict.get(opts, :timeout, 5000)
102-
conn_opts = Dict.drop(opts, [:timeout])
103-
noreply = Dict.get(opts, :noreply, false)
101+
timeout = Keyword.get(opts, :timeout, 5000)
102+
conn_opts = Keyword.drop(opts, [:timeout])
103+
noreply = Keyword.get(opts, :noreply, false)
104104
conn_opts = Connection.call(conn, :conn_opts)
105-
|> Dict.take([:db])
106-
|> Dict.merge(conn_opts)
105+
|> Map.to_list()
106+
|> Keyword.take([:db])
107+
|> Keyword.merge(conn_opts)
107108
query = prepare_and_encode(query, conn_opts)
108109
msg = case noreply do
109110
true -> {:query_noreply, query}
@@ -170,7 +171,7 @@ defmodule RethinkDB.Connection do
170171
@doc """
171172
Start connection as a linked process
172173
173-
Accepts a `Dict` of options. Supported options:
174+
Accepts a `Keyword.t` of options. Supported options:
174175
175176
* `:host` - hostname to use to connect to database. Defaults to `'localhost'`.
176177
* `:port` - port on which to connect to database. Defaults to `28015`.
@@ -182,26 +183,26 @@ defmodule RethinkDB.Connection do
182183
* `:ca_certs` - a list of file paths to cacerts.
183184
"""
184185
def start_link(opts \\ []) do
185-
args = Dict.take(opts, [:host, :port, :auth_key, :db, :sync_connect, :ssl, :max_pending])
186+
args = Keyword.take(opts, [:host, :port, :auth_key, :db, :sync_connect, :ssl, :max_pending])
186187
Connection.start_link(__MODULE__, args, opts)
187188
end
188189

189190
def init(opts) do
190-
host = case Dict.get(opts, :host, 'localhost') do
191+
host = case Keyword.get(opts, :host, 'localhost') do
191192
x when is_binary(x) -> String.to_char_list x
192193
x -> x
193194
end
194-
sync_connect = Dict.get(opts, :sync_connect, false)
195-
ssl = Dict.get(opts, :ssl)
196-
opts = Dict.put(opts, :host, host)
197-
|> Dict.put_new(:port, 28015)
198-
|> Dict.put_new(:auth_key, "")
199-
|> Dict.put_new(:max_pending, 10000)
200-
|> Dict.drop([:sync_connect])
195+
sync_connect = Keyword.get(opts, :sync_connect, false)
196+
ssl = Keyword.get(opts, :ssl)
197+
opts = Keyword.put(opts, :host, host)
198+
|> Keyword.put_new(:port, 28015)
199+
|> Keyword.put_new(:auth_key, "")
200+
|> Keyword.put_new(:max_pending, 10000)
201+
|> Keyword.drop([:sync_connect])
201202
|> Enum.into(%{})
202203
{transport, transport_opts} = case ssl do
203204
nil -> {%Transport.TCP{}, []}
204-
x -> {%Transport.SSL{}, Enum.map(Dict.fetch!(x, :ca_certs), &({:cacertfile, &1})) ++ [verify: :verify_peer]}
205+
x -> {%Transport.SSL{}, Enum.map(Keyword.fetch!(x, :ca_certs), &({:cacertfile, &1})) ++ [verify: :verify_peer]}
205206
end
206207
state = %{
207208
pending: %{},
@@ -228,11 +229,11 @@ defmodule RethinkDB.Connection do
228229
:ok ->
229230
:ok = Transport.setopts(socket, [active: :once])
230231
# TODO: investigate timeout vs hibernate
231-
{:ok, Dict.put(state, :socket, socket)}
232+
{:ok, Map.put(state, :socket, socket)}
232233
end
233234
{:error, :econnrefused} ->
234-
backoff = min(Dict.get(state, :timeout, 1000), 64000)
235-
{:backoff, backoff, Dict.put(state, :timeout, backoff*2)}
235+
backoff = min(Map.get(state, :timeout, 1000), 64000)
236+
{:backoff, backoff, Map.put(state, :timeout, backoff*2)}
236237
end
237238
end
238239

lib/rethinkdb/connection/request.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule RethinkDB.Connection.Request do
66
def make_request(query, token, from, state = %{pending: pending, socket: socket}) do
77
new_pending = case from do
88
:noreply -> pending
9-
_ -> Dict.put_new(pending, token, from)
9+
_ -> Map.put_new(pending, token, from)
1010
end
1111
bsize = :erlang.size(query)
1212
payload = token <> << bsize :: little-size(32) >> <> query
@@ -41,7 +41,7 @@ defmodule RethinkDB.Connection.Request do
4141
case leftover <> data do
4242
<< response :: binary-size(length), leftover :: binary >> ->
4343
Connection.reply(pending[token], {response, token})
44-
handle_recv("", %{state | current: {:start, leftover}, pending: Dict.delete(pending, token)})
44+
handle_recv("", %{state | current: {:start, leftover}, pending: Map.delete(pending, token)})
4545
new_data ->
4646
{:noreply, %{state | current: {:length, length, token, new_data}}}
4747
end

lib/rethinkdb/prepare.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ defmodule RethinkDB.Prepare do
2828
{Enum.into(map, %{}), state}
2929
end
3030
defp prepare(ref, state = {max, map}) when is_reference(ref) do
31-
case Dict.get(map,ref) do
32-
nil -> {max + 1, {max + 1, Dict.put_new(map, ref, max + 1)}}
31+
case Map.get(map, ref) do
32+
nil -> {max + 1, {max + 1, Map.put_new(map, ref, max + 1)}}
3333
x -> {x, state}
3434
end
3535
end
36-
defp prepare({k,v}, state) do
36+
defp prepare({k, v}, state) do
3737
{k, state} = prepare(k, state)
3838
{v, state} = prepare(v, state)
39-
{[k,v], state}
39+
{[k, v], state}
4040
end
4141
defp prepare(el, state) do
4242
{el, state}

lib/rethinkdb/query.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ defmodule RethinkDB.Query do
18601860

18611861
args = case arity do
18621862
0 -> []
1863-
_ -> Enum.map(1..arity, fn _ -> make_ref end)
1863+
_ -> Enum.map(1..arity, fn _ -> make_ref() end)
18641864
end
18651865
params = Enum.map(args, &var/1)
18661866

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ defmodule RethinkDB.Mixfile do use Mix.Project
55
version: "0.4.0",
66
elixir: "~> 1.0",
77
description: "RethinkDB driver for Elixir",
8-
package: package,
9-
deps: deps,
8+
package: package(),
9+
deps: deps(),
1010
test_coverage: [tool: ExCoveralls]]
1111
end
1212

test/changes_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ defmodule ChangesTest do
66

77
@table_name "changes_test_table_1"
88
setup_all do
9-
start_link
9+
start_link()
1010
table_create(@table_name) |> run
1111
on_exit fn ->
12-
start_link
12+
start_link()
1313
table_drop(@table_name) |> run
1414
end
1515
:ok
@@ -43,18 +43,18 @@ defmodule ChangesTest do
4343
q = table(@table_name) |> insert(data)
4444
{:ok, res} = run(q)
4545
expected = res.data["id"]
46-
{:ok, changes} = Task.await(t)
46+
{:ok, changes} = Task.await(t)
4747
^expected = changes.data |> hd |> Map.get("id")
4848

4949
# test Enumerable
5050
t = Task.async fn ->
51-
changes |> Enum.take(5)
51+
changes |> Enum.take(5)
5252
end
5353
1..6 |> Enum.each(fn _ ->
5454
q = table(@table_name) |> insert(data)
5555
run(q)
5656
end)
57-
data = Task.await(t)
57+
data = Task.await(t)
5858
5 = Enum.count(data)
5959
end
6060

test/connection_test.exs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ defmodule ConnectionTest do
2929
test "reconnects if initial connect fails" do
3030
{:ok, c} = start_link(port: 28014)
3131
Process.unlink(c)
32-
%RethinkDB.Exception.ConnectionClosed{} = table_list |> run
32+
%RethinkDB.Exception.ConnectionClosed{} = table_list() |> run
3333
conn = FlakyConnection.start('localhost', 28015, [local_port: 28014])
3434
:timer.sleep(1000)
35-
{:ok, %RethinkDB.Record{}} = RethinkDB.Query.table_list |> run
35+
{:ok, %RethinkDB.Record{}} = RethinkDB.Query.table_list() |> run
3636
ref = Process.monitor(c)
3737
FlakyConnection.stop(conn)
3838
receive do
@@ -47,7 +47,7 @@ defmodule ConnectionTest do
4747
table = "foo_flaky_test"
4848
RethinkDB.Query.table_create(table)|> run
4949
on_exit fn ->
50-
start_link
50+
start_link()
5151
:timer.sleep(100)
5252
RethinkDB.Query.table_drop(table) |> run
5353
GenServer.cast(__MODULE__, :stop)
@@ -84,15 +84,15 @@ defmodule ConnectionTest do
8484
{:ok, c} = RethinkDB.Connection.start_link(db: "new_test")
8585
db_create("new_test") |> RethinkDB.run(c)
8686
db("new_test") |> table_create("new_test_table") |> RethinkDB.run(c)
87-
{:ok, %{data: data}} = table_list |> RethinkDB.run(c)
87+
{:ok, %{data: data}} = table_list() |> RethinkDB.run(c)
8888
assert data == ["new_test_table"]
8989
end
9090

9191
test "connection accepts max_pending" do
9292
{:ok, c} = RethinkDB.Connection.start_link(max_pending: 1)
9393
res = Enum.map(1..100, fn (_) ->
9494
Task.async fn ->
95-
now |> RethinkDB.run(c)
95+
now() |> RethinkDB.run(c)
9696
end
9797
end) |> Enum.map(&Task.await/1)
9898
assert Enum.any?(res, &(&1 == %RethinkDB.Exception.TooManyRequests{}))
@@ -109,7 +109,7 @@ defmodule ConnectionTest do
109109
test "ssl connection" do
110110
conn = FlakyConnection.start('localhost', 28015, [ssl: [keyfile: "./test/cert/host.key", certfile: "./test/cert/host.crt"]])
111111
{:ok, c} = RethinkDB.Connection.start_link(port: conn.port, ssl: [ca_certs: ["./test/cert/rootCA.pem"]], sync_connect: true)
112-
{:ok, %{data: _}} = table_list |> RethinkDB.run(c)
112+
{:ok, %{data: _}} = table_list() |> RethinkDB.run(c)
113113
end
114114
end
115115

@@ -119,15 +119,15 @@ defmodule ConnectionRunTest do
119119
import RethinkDB.Query
120120

121121
setup_all do
122-
start_link
122+
start_link()
123123
:ok
124124
end
125125

126126
test "run(conn, opts) with :db option" do
127127
db_create("db_option_test") |> run
128128
table_create("db_option_test_table") |> run(db: "db_option_test")
129129

130-
{:ok, %{data: data}} = db("db_option_test") |> table_list |> run
130+
{:ok, %{data: data}} = db("db_option_test") |> table_list() |> run
131131

132132
db_drop("db_option_test") |> run
133133

@@ -149,7 +149,7 @@ defmodule ConnectionRunTest do
149149

150150
test "run with :noreply option" do
151151
:ok = make_array([1,2,3]) |> run(noreply: true)
152-
noreply_wait
152+
noreply_wait()
153153
end
154154

155155
test "run with :profile options" do

test/prepare_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ defmodule PrepareTest do
44

55
test "single elements" do
66
assert prepare(1) == 1
7-
assert prepare(make_ref) == 1
7+
assert prepare(make_ref()) == 1
88
end
99

1010
test "list" do
1111
assert prepare([1,2,3]) == [1,2,3]
12-
assert prepare([1,2,make_ref,make_ref]) == [1,2,1,2]
12+
assert prepare([1,2,make_ref(),make_ref()]) == [1,2,1,2]
1313
end
1414

1515
test "nested list" do
1616
list = [1, [1,2], [1, [1, 2]]]
1717
assert prepare(list) == list
18-
list = [1, [make_ref, make_ref], make_ref, [1, 2]]
18+
list = [1, [make_ref(), make_ref()], make_ref(), [1, 2]]
1919
assert prepare(list) == [1, [1, 2], 3, [1, 2]]
2020
end
2121

2222
test "map" do
2323
map = %{a: 1, b: 2}
2424
assert prepare(map) == map
25-
map = %{a: 1, b: make_ref, c: make_ref}
25+
map = %{a: 1, b: make_ref(), c: make_ref()}
2626
assert prepare(map) == %{a: 1, b: 1, c: 2}
2727
end
2828
end

test/query/administration_query_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule AdministrationQueryTest do
44
import RethinkDB.Query
55

66
setup_all do
7-
start_link
7+
start_link()
88
:ok
99
end
1010

@@ -16,7 +16,7 @@ defmodule AdministrationQueryTest do
1616
end
1717
:ok
1818
end
19-
19+
2020
test "config" do
2121
{:ok, r} = table(@table_name) |> config |> run
2222
assert %RethinkDB.Record{data: %{"db" => "test"}} = r

test/query/aggregation_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule AggregationTest do
1010
import RethinkDB.Lambda
1111

1212
setup_all do
13-
start_link
13+
start_link()
1414
:ok
1515
end
1616

test/query/control_structures_adv_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ defmodule ControlStructuresAdvTest do
77

88
@table_name "control_test_table_1"
99
setup_all do
10-
start_link
10+
start_link()
1111
q = table_create(@table_name)
1212
run(q)
1313
on_exit fn ->
14-
start_link
14+
start_link()
1515
table_drop(@table_name) |> run
1616
end
1717
:ok

test/query/control_structures_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule ControlStructuresTest do
77
alias RethinkDB.Response
88

99
setup_all do
10-
start_link
10+
start_link()
1111
:ok
1212
end
1313

@@ -39,10 +39,10 @@ defmodule ControlStructuresTest do
3939
test "branch" do
4040
q = branch(true, 1, 2)
4141
{:ok, %Record{data: data}} = run q
42-
assert data == 1
42+
assert data == 1
4343
q = branch(false, 1, 2)
4444
{:ok, %Record{data: data}} = run q
45-
assert data == 2
45+
assert data == 2
4646
end
4747

4848
test "error" do
@@ -105,7 +105,7 @@ defmodule ControlStructuresTest do
105105
end
106106

107107
test "uuid" do
108-
q = uuid
108+
q = uuid()
109109
{:ok, %Record{data: data}} = run q
110110
assert String.length(String.replace(data, "-", "")) == 32
111111
end

test/query/database_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule DatabaseTest do
66
alias RethinkDB.Record
77

88
setup_all do
9-
start_link
9+
start_link()
1010
:ok
1111
end
1212

@@ -29,14 +29,14 @@ defmodule DatabaseTest do
2929
q = db_create(@db_name)
3030
{:ok, %Record{data: %{"dbs_created" => 1}}} = run(q)
3131

32-
q = db_list
32+
q = db_list()
3333
{:ok, %Record{data: dbs}} = run(q)
3434
assert Enum.member?(dbs, @db_name)
3535

3636
q = db_drop(@db_name)
3737
{:ok, %Record{data: %{"dbs_dropped" => 1}}} = run(q)
3838

39-
q = db_list
39+
q = db_list()
4040
{:ok, %Record{data: dbs}} = run(q)
4141
assert !Enum.member?(dbs, @db_name)
4242
end

0 commit comments

Comments
 (0)