Mix format everything
This commit is contained in:
parent
1e620e0e84
commit
3ba1c322b8
|
|
@ -24,4 +24,3 @@ use Mix.Config
|
|||
# here (which is why it is important to import them last).
|
||||
#
|
||||
# import_config "#{Mix.env}.exs"
|
||||
|
||||
|
|
|
|||
15
lib/isn.ex
15
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 ->
|
||||
[<<IO.iodata_length(thing) :: int32>> | thing]
|
||||
[<<IO.iodata_length(thing)::int32>> | thing]
|
||||
end
|
||||
end
|
||||
|
||||
def decode(:copy) do
|
||||
quote do
|
||||
<<len :: int32, thing::binary-size(len)>> ->
|
||||
<<len::int32, thing::binary-size(len)>> ->
|
||||
:binary.copy(thing)
|
||||
end
|
||||
end
|
||||
|
||||
def decode(:reference) do
|
||||
quote do
|
||||
<<len :: int32, thing::binary-size(len)>> ->
|
||||
<<len::int32, thing::binary-size(len)>> ->
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
51
mix.exs
51
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
|
||||
|
|
|
|||
|
|
@ -16,4 +16,3 @@ defmodule ISN.EAN13Test do
|
|||
assert ISN.EAN13.dump(@test_ean) == {:ok, @test_ean}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,4 +16,3 @@ defmodule ISN.ISBNTest do
|
|||
assert ISN.ISBN.dump(@test_isbn) == {:ok, @test_isbn}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,4 +16,3 @@ defmodule ISN.ISMNTest do
|
|||
assert ISN.ISMN.dump(@test_ismn) == {:ok, @test_ismn}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,4 +16,3 @@ defmodule ISN.ISSNTest do
|
|||
assert ISN.ISSN.dump(@test_issn) == {:ok, @test_issn}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,5 +16,3 @@ defmodule ISN.UPCTest do
|
|||
assert ISN.UPC.dump(@test_upc) == {:ok, @test_upc}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;", [])
|
||||
|
|
|
|||
Loading…
Reference in New Issue