Rename Isn -> ISN

This commit is contained in:
Martin Frost 2016-01-10 12:12:38 +01:00
parent 04463fee19
commit 0cef21e3da
13 changed files with 67 additions and 67 deletions

View File

@ -1,8 +1,8 @@
# Isn # ISN
[![Build Status][4]][5] [![Build Status][4]][5]
Isn adds a [`Postgrex.Extension`][1] and [`Ecto.Type`][2] definitions ISN adds a [`Postgrex.Extension`][1] and [`Ecto.Type`][2] definitions
for the datatypes defined in the [`isn`][3] PostgreSQL module. for the datatypes defined in the [`isn`][3] PostgreSQL module.
## Usage ## Usage
@ -25,7 +25,7 @@ for the datatypes defined in the [`isn`][3] PostgreSQL module.
```elixir ```elixir
Postgrex.Connection.start_link( Postgrex.Connection.start_link(
database: "isn_test", database: "isn_test",
extensions: [{Isn, {}}]) extensions: [{ISN, {}}])
``` ```
4. Start using all of the `isn` goodness in your project. 4. Start using all of the `isn` goodness in your project.
@ -58,7 +58,7 @@ defmodule MyApp.Book do
use MyApp.Web, :model use MyApp.Web, :model
schema "books" do schema "books" do
field :isbn, Isn.ISBN13 field :isbn, ISN.ISBN13
# other fields # other fields
end end
end end
@ -66,18 +66,18 @@ end
## Defined types ## Defined types
`Isn` adds the following ecto and corresponding postgrex types: `ISN` adds the following ecto and corresponding postgrex types:
Ecto.Type | Postgrex type Ecto.Type | Postgrex type
-------------|-------------- -------------|--------------
`Isn.ISBN` | `:isbn` `ISN.ISBN` | `:isbn`
`Isn.ISBN13` | `:isbn13` `ISN.ISBN13` | `:isbn13`
`Isn.ISMN` | `:ismn` `ISN.ISMN` | `:ismn`
`Isn.ISMN13` | `:ismn13` `ISN.ISMN13` | `:ismn13`
`Isn.ISSN` | `:issn` `ISN.ISSN` | `:issn`
`Isn.ISSN13` | `:issn13` `ISN.ISSN13` | `:issn13`
`Isn.EAN13` | `:ean13` `ISN.EAN13` | `:ean13`
`Isn.UPC` | `:upc` `ISN.UPC` | `:upc`
[1]: http://hexdocs.pm/postgrex/Postgrex.Extension.html [1]: http://hexdocs.pm/postgrex/Postgrex.Extension.html
[2]: http://hexdocs.pm/ecto/Ecto.Type.html [2]: http://hexdocs.pm/ecto/Ecto.Type.html

View File

@ -1,4 +1,4 @@
defmodule Isn do defmodule ISN do
alias Postgrex.TypeInfo alias Postgrex.TypeInfo
@behaviour Postgrex.Extension @behaviour Postgrex.Extension
@ -12,7 +12,7 @@ defmodule Isn do
Postgrex.Connection.start_link( Postgrex.Connection.start_link(
database: "isn_test", database: "isn_test",
extensions: [{Isn, {}}]) extensions: [{ISN, {}}])
Then you can do Ecto.Migrations like this: Then you can do Ecto.Migrations like this:
@ -33,7 +33,7 @@ defmodule Isn do
use MyApp.Web, :model use MyApp.Web, :model
schema "books" do schema "books" do
field :isbn, Isn.ISBN13 field :isbn, ISN.ISBN13
# other fields # other fields
end end
end end
@ -58,14 +58,14 @@ end
# Generate Ecto.Type modules for all supported data types in the `isn` # Generate Ecto.Type modules for all supported data types in the `isn`
# postgresql module. # postgresql module.
for module <- ~w(ISBN ISMN ISSN ISBN13 ISMN13 ISSN13 UPC EAN13) do for module <- ~w(ISBN ISMN ISSN ISBN13 ISMN13 ISSN13 UPC EAN13) do
module_name = Module.concat([Isn, module]) 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 defmodule module_name do
@behaviour Ecto.Type @behaviour Ecto.Type
@moduledoc """ @moduledoc """
Definition for the Isn.#{module} module. Definition for the ISN.#{module} module.
How to use this in an Ecto.Model How to use this in an Ecto.Model
@ -73,7 +73,7 @@ for module <- ~w(ISBN ISMN ISSN ISBN13 ISMN13 ISSN13 UPC EAN13) do
use MyApp.Web, :model use MyApp.Web, :model
schema "books" do schema "books" do
field :#{ecto_type}, Isn.#{module} field :#{ecto_type}, ISN.#{module}
# other fields # other fields
end end
end end

View File

@ -1,4 +1,4 @@
defmodule Isn.Mixfile do defmodule ISN.Mixfile do
use Mix.Project use Mix.Project
@version "0.1.2" @version "0.1.2"
@ -13,7 +13,7 @@ defmodule Isn.Mixfile do
description: description, description: description,
package: package, package: package,
# Docs # Docs
name: "Isn", name: "ISN",
docs: [source_ref: "v#{@version}", docs: [source_ref: "v#{@version}",
source_url: "https://github.com/Frost/isn"] source_url: "https://github.com/Frost/isn"]
] ]

View File

@ -1,19 +1,19 @@
defmodule Isn.EAN13Test do defmodule ISN.EAN13Test do
use ExUnit.Case, async: true use ExUnit.Case, async: true
@test_ean "022-035648348-1" @test_ean "022-035648348-1"
test "cast" do test "cast" do
assert Isn.EAN13.cast(@test_ean) == {:ok, @test_ean} assert ISN.EAN13.cast(@test_ean) == {:ok, @test_ean}
assert Isn.EAN13.cast(nil) == :error assert ISN.EAN13.cast(nil) == :error
end end
test "load" do test "load" do
assert Isn.EAN13.load(@test_ean) == {:ok, @test_ean} assert ISN.EAN13.load(@test_ean) == {:ok, @test_ean}
end end
test "dump" do test "dump" do
assert Isn.EAN13.dump(@test_ean) == {:ok, @test_ean} assert ISN.EAN13.dump(@test_ean) == {:ok, @test_ean}
end end
end end

View File

@ -1,18 +1,18 @@
defmodule Isn.ISBN13Test do defmodule ISN.ISBN13Test do
use ExUnit.Case, async: true use ExUnit.Case, async: true
@test_isbn "978-1-937785-58-1" @test_isbn "978-1-937785-58-1"
test "cast" do test "cast" do
assert Isn.ISBN13.cast(@test_isbn) == {:ok, @test_isbn} assert ISN.ISBN13.cast(@test_isbn) == {:ok, @test_isbn}
assert Isn.ISBN13.cast(nil) == :error assert ISN.ISBN13.cast(nil) == :error
end end
test "load" do test "load" do
assert Isn.ISBN13.load(@test_isbn) == {:ok, @test_isbn} assert ISN.ISBN13.load(@test_isbn) == {:ok, @test_isbn}
end end
test "dump" do test "dump" do
assert Isn.ISBN13.dump(@test_isbn) == {:ok, @test_isbn} assert ISN.ISBN13.dump(@test_isbn) == {:ok, @test_isbn}
end end
end end

View File

@ -1,19 +1,19 @@
defmodule Isn.ISBNTest do defmodule ISN.ISBNTest do
use ExUnit.Case, async: true use ExUnit.Case, async: true
@test_isbn "1-937785-58-0" @test_isbn "1-937785-58-0"
test "cast" do test "cast" do
assert Isn.ISBN.cast(@test_isbn) == {:ok, @test_isbn} assert ISN.ISBN.cast(@test_isbn) == {:ok, @test_isbn}
assert Isn.ISBN.cast(nil) == :error assert ISN.ISBN.cast(nil) == :error
end end
test "load" do test "load" do
assert Isn.ISBN.load(@test_isbn) == {:ok, @test_isbn} assert ISN.ISBN.load(@test_isbn) == {:ok, @test_isbn}
end end
test "dump" do test "dump" do
assert Isn.ISBN.dump(@test_isbn) == {:ok, @test_isbn} assert ISN.ISBN.dump(@test_isbn) == {:ok, @test_isbn}
end end
end end

View File

@ -1,18 +1,18 @@
defmodule Isn.ISMN13Test do defmodule ISN.ISMN13Test do
use ExUnit.Case, async: true use ExUnit.Case, async: true
@test_ismn "979-0-060-11561-5" @test_ismn "979-0-060-11561-5"
test "cast" do test "cast" do
assert Isn.ISMN13.cast(@test_ismn) == {:ok, @test_ismn} assert ISN.ISMN13.cast(@test_ismn) == {:ok, @test_ismn}
assert Isn.ISMN13.cast(nil) == :error assert ISN.ISMN13.cast(nil) == :error
end end
test "load" do test "load" do
assert Isn.ISMN13.load(@test_ismn) == {:ok, @test_ismn} assert ISN.ISMN13.load(@test_ismn) == {:ok, @test_ismn}
end end
test "dump" do test "dump" do
assert Isn.ISMN13.dump(@test_ismn) == {:ok, @test_ismn} assert ISN.ISMN13.dump(@test_ismn) == {:ok, @test_ismn}
end end
end end

View File

@ -1,19 +1,19 @@
defmodule Isn.ISMNTest do defmodule ISN.ISMNTest do
use ExUnit.Case, async: true use ExUnit.Case, async: true
@test_ismn "M-060-11561-5" @test_ismn "M-060-11561-5"
test "cast" do test "cast" do
assert Isn.ISMN.cast(@test_ismn) == {:ok, @test_ismn} assert ISN.ISMN.cast(@test_ismn) == {:ok, @test_ismn}
assert Isn.ISMN.cast(nil) == :error assert ISN.ISMN.cast(nil) == :error
end end
test "load" do test "load" do
assert Isn.ISMN.load(@test_ismn) == {:ok, @test_ismn} assert ISN.ISMN.load(@test_ismn) == {:ok, @test_ismn}
end end
test "dump" do test "dump" do
assert Isn.ISMN.dump(@test_ismn) == {:ok, @test_ismn} assert ISN.ISMN.dump(@test_ismn) == {:ok, @test_ismn}
end end
end end

View File

@ -1,18 +1,18 @@
defmodule Isn.ISSN13Test do defmodule ISN.ISSN13Test do
use ExUnit.Case, async: true use ExUnit.Case, async: true
@test_issn "977-1436-452-00-8" @test_issn "977-1436-452-00-8"
test "cast" do test "cast" do
assert Isn.ISSN13.cast(@test_issn) == {:ok, @test_issn} assert ISN.ISSN13.cast(@test_issn) == {:ok, @test_issn}
assert Isn.ISSN13.cast(nil) == :error assert ISN.ISSN13.cast(nil) == :error
end end
test "load" do test "load" do
assert Isn.ISSN13.load(@test_issn) == {:ok, @test_issn} assert ISN.ISSN13.load(@test_issn) == {:ok, @test_issn}
end end
test "dump" do test "dump" do
assert Isn.ISSN13.dump(@test_issn) == {:ok, @test_issn} assert ISN.ISSN13.dump(@test_issn) == {:ok, @test_issn}
end end
end end

View File

@ -1,19 +1,19 @@
defmodule Isn.ISSNTest do defmodule ISN.ISSNTest do
use ExUnit.Case, async: true use ExUnit.Case, async: true
@test_issn "1436-4522" @test_issn "1436-4522"
test "cast" do test "cast" do
assert Isn.ISSN.cast(@test_issn) == {:ok, @test_issn} assert ISN.ISSN.cast(@test_issn) == {:ok, @test_issn}
assert Isn.ISSN.cast(nil) == :error assert ISN.ISSN.cast(nil) == :error
end end
test "load" do test "load" do
assert Isn.ISSN.load(@test_issn) == {:ok, @test_issn} assert ISN.ISSN.load(@test_issn) == {:ok, @test_issn}
end end
test "dump" do test "dump" do
assert Isn.ISSN.dump(@test_issn) == {:ok, @test_issn} assert ISN.ISSN.dump(@test_issn) == {:ok, @test_issn}
end end
end end

View File

@ -1,19 +1,19 @@
defmodule Isn.UPCTest do defmodule ISN.UPCTest do
use ExUnit.Case, async: true use ExUnit.Case, async: true
@test_upc "220356483481" @test_upc "220356483481"
test "cast" do test "cast" do
assert Isn.UPC.cast(@test_upc) == {:ok, @test_upc} assert ISN.UPC.cast(@test_upc) == {:ok, @test_upc}
assert Isn.UPC.cast(nil) == :error assert ISN.UPC.cast(nil) == :error
end end
test "load" do test "load" do
assert Isn.UPC.load(@test_upc) == {:ok, @test_upc} assert ISN.UPC.load(@test_upc) == {:ok, @test_upc}
end end
test "dump" do test "dump" do
assert Isn.UPC.dump(@test_upc) == {:ok, @test_upc} assert ISN.UPC.dump(@test_upc) == {:ok, @test_upc}
end end
end end

View File

@ -1,10 +1,10 @@
defmodule IsnTest do defmodule ISNTest do
use ExUnit.Case, async: true use ExUnit.Case, async: true
import Isn.TestHelper import ISN.TestHelper
alias Postgrex.Connection, as: P alias Postgrex.Connection, as: P
setup do setup do
options = Keyword.merge(conn_options, [extensions: [{Isn, {}}]]) options = Keyword.merge(conn_options, [extensions: [{ISN, {}}]])
{:ok, pid} = P.start_link(options) {:ok, pid} = P.start_link(options)
{:ok, [pid: pid]} {:ok, [pid: pid]}
end end

View File

@ -18,7 +18,7 @@ ExUnit.start()
# {:ok, pid} = Postgrex.Connection.start_link(conn_options) # {:ok, pid} = Postgrex.Connection.start_link(conn_options)
# Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", []) # Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", [])
defmodule Isn.TestHelper do defmodule ISN.TestHelper do
def conn_options do def conn_options do
db_options = [ db_options = [
sync_connect: true, sync_connect: true,
@ -47,12 +47,12 @@ defmodule Isn.TestHelper do
end end
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.Connection.start_link(db_options) {:ok, pid} = Postgrex.Connection.start_link(db_options)
Postgrex.Connection.query!(pid, "DROP DATABASE IF EXISTS isn_test;", []) Postgrex.Connection.query!(pid, "DROP DATABASE IF EXISTS isn_test;", [])
Postgrex.Connection.query!(pid, "CREATE DATABASE isn_test;", []) Postgrex.Connection.query!(pid, "CREATE DATABASE isn_test;", [])
Postgrex.Connection.stop(pid) Postgrex.Connection.stop(pid)
{:ok, pid} = Postgrex.Connection.start_link(Isn.TestHelper.conn_options) {:ok, pid} = Postgrex.Connection.start_link(ISN.TestHelper.conn_options)
Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", []) Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", [])
Postgrex.Connection.stop(pid) Postgrex.Connection.stop(pid)