From 3ba1c322b8723d8a5e95cb30431004db84a6e548 Mon Sep 17 00:00:00 2001 From: Martin Frost Date: Fri, 26 Jan 2018 17:55:15 +0100 Subject: [PATCH] Mix format everything --- config/config.exs | 1 - lib/isn.ex | 15 +++++----- lib/tasks/isn.gen.migration.ex | 10 +++---- mix.exs | 51 +++++++++++++++++++--------------- test/isn/ean13_test.exs | 1 - test/isn/isbn_test.exs | 1 - test/isn/ismn_test.exs | 1 - test/isn/issn_test.exs | 1 - test/isn/upc_test.exs | 2 -- test/isn_test.exs | 26 ++++++----------- test/test_helper.exs | 13 ++++----- 11 files changed, 56 insertions(+), 66 deletions(-) diff --git a/config/config.exs b/config/config.exs index 27a6afa..136603b 100644 --- a/config/config.exs +++ b/config/config.exs @@ -24,4 +24,3 @@ use Mix.Config # here (which is why it is important to import them last). # # import_config "#{Mix.env}.exs" - diff --git a/lib/isn.ex b/lib/isn.ex index c7b8358..ba6c4c0 100644 --- a/lib/isn.ex +++ b/lib/isn.ex @@ -46,28 +46,27 @@ defmodule ISN do def init(opts), do: Keyword.get(opts, :decode_copy, :reference) - def matching(_), - do: Enum.zip(Stream.cycle([:type]), @isn) + def matching(_), do: Enum.zip(Stream.cycle([:type]), @isn) - def format(_), - do: :text + def format(_), do: :text def encode(_opts) do quote do thing -> - [<> | thing] + [<> | thing] end end def decode(:copy) do quote do - <> -> + <> -> :binary.copy(thing) end end + def decode(:reference) do quote do - <> -> + <> -> thing end end @@ -77,7 +76,7 @@ end # postgresql module. for module <- ~w(ISBN ISMN ISSN ISBN13 ISMN13 ISSN13 UPC EAN13) do module_name = Module.concat([ISN, module]) - ecto_type = module |> String.downcase |> String.to_atom + ecto_type = module |> String.downcase() |> String.to_atom() defmodule module_name do @behaviour Ecto.Type diff --git a/lib/tasks/isn.gen.migration.ex b/lib/tasks/isn.gen.migration.ex index 30914b3..d8c9088 100644 --- a/lib/tasks/isn.gen.migration.ex +++ b/lib/tasks/isn.gen.migration.ex @@ -17,10 +17,10 @@ defmodule Mix.Tasks.Isn.Gen.Migration do @doc false def run(args) do - Mix.Task.run "app.start", args + Mix.Task.run("app.start", args) [repo] = parse_repo(args) filename = "#{timestamp()}_create_isn_extension.exs" - path = Path.relative_to(migrations_path(repo), Mix.Project.app_path) + path = Path.relative_to(migrations_path(repo), Mix.Project.app_path()) file = Path.join(path, filename) create_directory(path) mod = Module.concat([repo, Migrations, @migration_name]) @@ -32,9 +32,9 @@ defmodule Mix.Tasks.Isn.Gen.Migration do "#{y}#{pad(m)}#{pad(d)}#{pad(hh)}#{pad(mm)}#{pad(ss)}" end - defp pad(s), do: s |> to_string() |> String.rjust(2, ?0) + defp pad(s), do: s |> to_string() |> String.pad_leading(2, ?0) - embed_template :migration, """ + embed_template(:migration, """ defmodule <%= inspect @mod %> do use Ecto.Migration @@ -46,5 +46,5 @@ defmodule Mix.Tasks.Isn.Gen.Migration do execute "DROP EXTENSION IF EXISTS isn;" end end - """ + """) end diff --git a/mix.exs b/mix.exs index 9fb104d..02666f8 100644 --- a/mix.exs +++ b/mix.exs @@ -4,20 +4,23 @@ defmodule ISN.Mixfile do @version "2.0.0" def project do - [app: :isn, - version: @version, - elixir: "~> 1.0", - deps: deps(), - test_paths: ["test"], - # Hex - description: description(), - package: package(), - # Docs - name: "ISN", - docs: [source_ref: "v#{@version}", - source_url: "https://github.com/Frost/isn", - extras: ["README.md"]] - ] + [ + app: :isn, + version: @version, + elixir: "~> 1.0", + deps: deps(), + test_paths: ["test"], + # Hex + description: description(), + package: package(), + # Docs + name: "ISN", + docs: [ + source_ref: "v#{@version}", + source_url: "https://github.com/Frost/isn", + extras: ["README.md"] + ] + ] end # Configuration for the OTP application @@ -34,16 +37,20 @@ defmodule ISN.Mixfile do end defp package do - [files: ~w(lib README.md mix.exs), - maintainers: ["Martin Frost"], - licenses: ["Apache 2.0"], - links: %{"GitHub" => "https://github.com/Frost/isn"}] + [ + files: ~w(lib README.md mix.exs), + maintainers: ["Martin Frost"], + licenses: ["Apache 2.0"], + links: %{"GitHub" => "https://github.com/Frost/isn"} + ] end defp deps do - [{:postgrex, ">= 0.13.2"}, - {:ecto, ">= 2.1.4"}, - {:credo, "~> 0.7", only: :dev}, - {:ex_doc, "~> 0.15", only: :dev}] + [ + {:postgrex, ">= 0.13.2"}, + {:ecto, ">= 2.1.4"}, + {:credo, "~> 0.7", only: :dev}, + {:ex_doc, "~> 0.15", only: :dev} + ] end end diff --git a/test/isn/ean13_test.exs b/test/isn/ean13_test.exs index d4d2a4b..bc154c1 100644 --- a/test/isn/ean13_test.exs +++ b/test/isn/ean13_test.exs @@ -16,4 +16,3 @@ defmodule ISN.EAN13Test do assert ISN.EAN13.dump(@test_ean) == {:ok, @test_ean} end end - diff --git a/test/isn/isbn_test.exs b/test/isn/isbn_test.exs index 186c7e1..5fc4610 100644 --- a/test/isn/isbn_test.exs +++ b/test/isn/isbn_test.exs @@ -16,4 +16,3 @@ defmodule ISN.ISBNTest do assert ISN.ISBN.dump(@test_isbn) == {:ok, @test_isbn} end end - diff --git a/test/isn/ismn_test.exs b/test/isn/ismn_test.exs index 854e461..8d719e7 100644 --- a/test/isn/ismn_test.exs +++ b/test/isn/ismn_test.exs @@ -16,4 +16,3 @@ defmodule ISN.ISMNTest do assert ISN.ISMN.dump(@test_ismn) == {:ok, @test_ismn} end end - diff --git a/test/isn/issn_test.exs b/test/isn/issn_test.exs index e0847de..761439a 100644 --- a/test/isn/issn_test.exs +++ b/test/isn/issn_test.exs @@ -16,4 +16,3 @@ defmodule ISN.ISSNTest do assert ISN.ISSN.dump(@test_issn) == {:ok, @test_issn} end end - diff --git a/test/isn/upc_test.exs b/test/isn/upc_test.exs index c144466..b38ae22 100644 --- a/test/isn/upc_test.exs +++ b/test/isn/upc_test.exs @@ -16,5 +16,3 @@ defmodule ISN.UPCTest do assert ISN.UPC.dump(@test_upc) == {:ok, @test_upc} end end - - diff --git a/test/isn_test.exs b/test/isn_test.exs index e1dfa73..6192791 100644 --- a/test/isn_test.exs +++ b/test/isn_test.exs @@ -4,48 +4,40 @@ defmodule ISNTest do alias Postgrex, as: P setup do - options = Keyword.merge(conn_options(), [extensions: [{ISN, {}}]]) + options = Keyword.merge(conn_options(), extensions: [{ISN, {}}]) {:ok, pid} = P.start_link(options) {:ok, [pid: pid]} end test "encode and decode isbn", context do - assert [["1-937785-58-0"]] = - query(context[:pid], "SELECT $1::isbn", ['1937785580']) + assert [["1-937785-58-0"]] = query(context[:pid], "SELECT $1::isbn", ['1937785580']) end test "encode and decode isbn13", context do - assert [["978-1-937785-58-1"]] = - query(context[:pid], "SELECT $1::isbn13", ['9781937785581']) + assert [["978-1-937785-58-1"]] = query(context[:pid], "SELECT $1::isbn13", ['9781937785581']) end test "encode and decode ismn", context do - assert [["M-060-11561-5"]] = - query(context[:pid], "SELECT $1::ismn", ['9790060115615']) + assert [["M-060-11561-5"]] = query(context[:pid], "SELECT $1::ismn", ['9790060115615']) end test "encode and decode ismn13", context do - assert [["979-0-060-11561-5"]] = - query(context[:pid], "SELECT $1::ismn13", ['9790060115615']) + assert [["979-0-060-11561-5"]] = query(context[:pid], "SELECT $1::ismn13", ['9790060115615']) end test "encode and decode issn", context do - assert [["1436-4522"]] = - query(context[:pid], "SELECT $1::issn", ['14364522']) + assert [["1436-4522"]] = query(context[:pid], "SELECT $1::issn", ['14364522']) end test "encode and decode issn13", context do - assert [["977-1436-452-00-8"]] = - query(context[:pid], "SELECT issn13(issn('1436-4522'))", []) + assert [["977-1436-452-00-8"]] = query(context[:pid], "SELECT issn13(issn('1436-4522'))", []) end test "encode and decode ean13", context do - assert [["022-035648348-1"]] = - query(context[:pid], "SELECT $1::ean13", ["0220356483481"]) + assert [["022-035648348-1"]] = query(context[:pid], "SELECT $1::ean13", ["0220356483481"]) end test "encode and decode upc", context do - assert [["220356483481"]] = - query(context[:pid], "SELECT $1::upc", ["220356483481"]) + assert [["220356483481"]] = query(context[:pid], "SELECT $1::upc", ["220356483481"]) end end diff --git a/test/test_helper.exs b/test/test_helper.exs index 7c9ad5e..04c7824 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,8 +1,5 @@ ExUnit.start() -Postgrex.Types.define( - ISN.PostgrexTypes, - [ISN], - []) +Postgrex.Types.define(ISN.PostgrexTypes, [ISN], []) defmodule ISN.TestHelper do def conn_options do @@ -10,7 +7,8 @@ defmodule ISN.TestHelper do sync_connect: true, hostname: "localhost", types: ISN.PostgrexTypes, - database: "isn_test"] + database: "isn_test" + ] db_user = System.get_env("DATABASE_POSTGRESQL_USERNAME") db_pass = System.get_env("DATABASE_POSTGRESQL_PASSWORD") @@ -21,6 +19,7 @@ defmodule ISN.TestHelper do else db_options end + db_options = if db_pass do Keyword.put(db_options, :password, db_pass) @@ -42,10 +41,10 @@ defmodule ISN.TestHelper do end end -db_options = Keyword.merge(ISN.TestHelper.conn_options, [database: "postgres"]) +db_options = Keyword.merge(ISN.TestHelper.conn_options(), database: "postgres") {:ok, pid} = Postgrex.start_link(db_options) Postgrex.query!(pid, "DROP DATABASE IF EXISTS isn_test;", []) Postgrex.query!(pid, "CREATE DATABASE isn_test;", []) -{:ok, pid} = Postgrex.start_link(ISN.TestHelper.conn_options) +{:ok, pid} = Postgrex.start_link(ISN.TestHelper.conn_options()) Postgrex.query!(pid, "CREATE EXTENSION isn;", [])