aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Schaefermeyer <michael.schaefermeyer@gmail.com>2016-09-02 10:57:38 +0200
committerMichael Schaefermeyer <michael.schaefermeyer@gmail.com>2016-09-02 10:57:41 +0200
commit5654e5f14dd42fb36268995323dc526d335d00a9 (patch)
tree3e05012fc36e9d425b6157779db5067d089f315e /lib
parent01d2c03837b964da81a0195e7b0c6a7257e49756 (diff)
downloadboltex-5654e5f14dd42fb36268995323dc526d335d00a9.tar.gz
boltex-5654e5f14dd42fb36268995323dc526d335d00a9.tar.xz
Refactor following credo
Diffstat (limited to 'lib')
-rw-r--r--lib/boltex.ex8
-rw-r--r--lib/boltex/bolt.ex8
-rw-r--r--lib/boltex/pack_stream.ex10
-rw-r--r--lib/boltex/utils.ex6
4 files changed, 19 insertions, 13 deletions
diff --git a/lib/boltex.ex b/lib/boltex.ex
index 992009f..a5b2bbf 100644
--- a/lib/boltex.ex
+++ b/lib/boltex.ex
@@ -1,4 +1,10 @@
defmodule Boltex do
+ @moduledoc """
+ Elixir library for using the Neo4J Bolt Protocol.
+
+ It supports de- and encoding of Boltex binaries and sending and receiving
+ of data using the Bolt protocol.
+ """
alias Boltex.Bolt
def test(host, port, query, params \\ %{}, auth \\ nil) do
@@ -7,7 +13,7 @@ defmodule Boltex do
:ok = Bolt.handshake :gen_tcp, p
:ok = Bolt.init :gen_tcp, p, auth
- IO.inspect Bolt.run_statement(:gen_tcp, p, query)
+ Bolt.run_statement(:gen_tcp, p, query)
end
end
diff --git a/lib/boltex/bolt.ex b/lib/boltex/bolt.ex
index 984d0b6..d433ea6 100644
--- a/lib/boltex/bolt.ex
+++ b/lib/boltex/bolt.ex
@@ -89,7 +89,8 @@ defmodule Boltex.Bolt do
Messages have to be in the form of {[messages], signature}.
"""
def send_messages(transport, port, messages) do
- Enum.map(messages, &generate_binary_message/1)
+ messages
+ |> Enum.map(&generate_binary_message/1)
|> generate_chunks
|> Enum.each(&(transport.send(port, &1)))
end
@@ -151,7 +152,7 @@ defmodule Boltex.Bolt do
]
with {:success, %{}} = data <- receive_data(transport, port),
- do: [data | receive_data(transport, port) |> List.wrap]
+ do: [data | transport |> receive_data(port) |> List.wrap]
end
@doc """
@@ -178,7 +179,7 @@ defmodule Boltex.Bolt do
* `:failure`
"""
def receive_data(transport, port, previous \\ []) do
- case do_receive_data(transport, port) |> unpack do
+ case transport |> do_receive_data(transport) |> unpack do
{:record, _} = data ->
receive_data transport, port, [data | previous]
@@ -207,7 +208,6 @@ defmodule Boltex.Bolt do
{:error, :timeout} ->
{:error, :no_more_data_received}
other ->
- IO.inspect Utils.hex_encode other
raise "receive failed"
end
end
diff --git a/lib/boltex/pack_stream.ex b/lib/boltex/pack_stream.ex
index 736351f..aeca3a9 100644
--- a/lib/boltex/pack_stream.ex
+++ b/lib/boltex/pack_stream.ex
@@ -56,9 +56,8 @@ defmodule Boltex.PackStream do
def decode(<< 0xD5, list_size :: 16 >> <> bin), do: list(bin, list_size)
def decode(<< 0xD6, list_size :: 32 >> <> bin), do: list(bin, list_size)
def decode(<< 0xD7 >> <> bin) do
- position =
- for(<< byte <- bin >>, do: byte)
- |> Enum.find_index(&(&1 == 0xDF))
+ bytes = for(<< byte <- bin >>, do: byte)
+ position = Enum.find_index bytes, &(&1 == 0xDF)
<< list :: binary-size(position), 0xDF, rest :: binary >> = bin
@@ -71,9 +70,8 @@ defmodule Boltex.PackStream do
def decode(<< 0xD9, entries :: 16 >> <> bin), do: map(bin, entries)
def decode(<< 0xDA, entries :: 32 >> <> bin), do: map(bin, entries)
def decode(<< 0xDB >> <> bin) do
- position =
- for(<< byte <- bin >>, do: byte)
- |> Enum.find_index(&(&1 == 0xDF))
+ bytes = for(<< byte <- bin >>, do: byte)
+ position = Enum.find_index bytes, &(&1 == 0xDF)
<< map:: binary-size(position), 0xDF, rest :: binary >> = bin
diff --git a/lib/boltex/utils.ex b/lib/boltex/utils.ex
index 333217e..fea5759 100644
--- a/lib/boltex/utils.ex
+++ b/lib/boltex/utils.ex
@@ -1,4 +1,6 @@
defmodule Boltex.Utils do
+ @moduledoc "Different utils used to debugging and helping."
+
def reduce_to_binary(enumerable, transform) do
Enum.reduce enumerable, <<>>, fn(data, acc) -> acc <> transform.(data) end
end
@@ -8,7 +10,7 @@ defmodule Boltex.Utils do
end
def hex_decode(hex_list) do
- for(hex <- hex_list, do: Integer.parse(hex, 16) |> elem(0))
- |> reduce_to_binary(&<<&1>>)
+ integers = for(hex <- hex_list, do: hex |> Integer.parse(16) |> elem(0))
+ reduce_to_binary integer, &<<&1>>
end
end