Rename Isn -> ISN
This commit is contained in:
parent
04463fee19
commit
0cef21e3da
26
README.md
26
README.md
|
|
@ -1,8 +1,8 @@
|
|||
# Isn
|
||||
# ISN
|
||||
|
||||
[![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.
|
||||
|
||||
## Usage
|
||||
|
|
@ -25,7 +25,7 @@ for the datatypes defined in the [`isn`][3] PostgreSQL module.
|
|||
```elixir
|
||||
Postgrex.Connection.start_link(
|
||||
database: "isn_test",
|
||||
extensions: [{Isn, {}}])
|
||||
extensions: [{ISN, {}}])
|
||||
```
|
||||
4. Start using all of the `isn` goodness in your project.
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ defmodule MyApp.Book do
|
|||
use MyApp.Web, :model
|
||||
|
||||
schema "books" do
|
||||
field :isbn, Isn.ISBN13
|
||||
field :isbn, ISN.ISBN13
|
||||
# other fields
|
||||
end
|
||||
end
|
||||
|
|
@ -66,18 +66,18 @@ end
|
|||
|
||||
## Defined types
|
||||
|
||||
`Isn` adds the following ecto and corresponding postgrex types:
|
||||
`ISN` adds the following ecto and corresponding postgrex types:
|
||||
|
||||
Ecto.Type | Postgrex type
|
||||
-------------|--------------
|
||||
`Isn.ISBN` | `:isbn`
|
||||
`Isn.ISBN13` | `:isbn13`
|
||||
`Isn.ISMN` | `:ismn`
|
||||
`Isn.ISMN13` | `:ismn13`
|
||||
`Isn.ISSN` | `:issn`
|
||||
`Isn.ISSN13` | `:issn13`
|
||||
`Isn.EAN13` | `:ean13`
|
||||
`Isn.UPC` | `:upc`
|
||||
`ISN.ISBN` | `:isbn`
|
||||
`ISN.ISBN13` | `:isbn13`
|
||||
`ISN.ISMN` | `:ismn`
|
||||
`ISN.ISMN13` | `:ismn13`
|
||||
`ISN.ISSN` | `:issn`
|
||||
`ISN.ISSN13` | `:issn13`
|
||||
`ISN.EAN13` | `:ean13`
|
||||
`ISN.UPC` | `:upc`
|
||||
|
||||
[1]: http://hexdocs.pm/postgrex/Postgrex.Extension.html
|
||||
[2]: http://hexdocs.pm/ecto/Ecto.Type.html
|
||||
|
|
|
|||
12
lib/isn.ex
12
lib/isn.ex
|
|
@ -1,4 +1,4 @@
|
|||
defmodule Isn do
|
||||
defmodule ISN do
|
||||
alias Postgrex.TypeInfo
|
||||
|
||||
@behaviour Postgrex.Extension
|
||||
|
|
@ -12,7 +12,7 @@ defmodule Isn do
|
|||
|
||||
Postgrex.Connection.start_link(
|
||||
database: "isn_test",
|
||||
extensions: [{Isn, {}}])
|
||||
extensions: [{ISN, {}}])
|
||||
|
||||
Then you can do Ecto.Migrations like this:
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ defmodule Isn do
|
|||
use MyApp.Web, :model
|
||||
|
||||
schema "books" do
|
||||
field :isbn, Isn.ISBN13
|
||||
field :isbn, ISN.ISBN13
|
||||
# other fields
|
||||
end
|
||||
end
|
||||
|
|
@ -58,14 +58,14 @@ end
|
|||
# Generate Ecto.Type modules for all supported data types in the `isn`
|
||||
# postgresql module.
|
||||
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
|
||||
|
||||
defmodule module_name do
|
||||
@behaviour Ecto.Type
|
||||
|
||||
@moduledoc """
|
||||
Definition for the Isn.#{module} module.
|
||||
Definition for the ISN.#{module} module.
|
||||
|
||||
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
|
||||
|
||||
schema "books" do
|
||||
field :#{ecto_type}, Isn.#{module}
|
||||
field :#{ecto_type}, ISN.#{module}
|
||||
# other fields
|
||||
end
|
||||
end
|
||||
|
|
|
|||
4
mix.exs
4
mix.exs
|
|
@ -1,4 +1,4 @@
|
|||
defmodule Isn.Mixfile do
|
||||
defmodule ISN.Mixfile do
|
||||
use Mix.Project
|
||||
|
||||
@version "0.1.2"
|
||||
|
|
@ -13,7 +13,7 @@ defmodule Isn.Mixfile do
|
|||
description: description,
|
||||
package: package,
|
||||
# Docs
|
||||
name: "Isn",
|
||||
name: "ISN",
|
||||
docs: [source_ref: "v#{@version}",
|
||||
source_url: "https://github.com/Frost/isn"]
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
defmodule Isn.EAN13Test do
|
||||
defmodule ISN.EAN13Test do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
@test_ean "022-035648348-1"
|
||||
|
||||
test "cast" do
|
||||
assert Isn.EAN13.cast(@test_ean) == {:ok, @test_ean}
|
||||
assert Isn.EAN13.cast(nil) == :error
|
||||
assert ISN.EAN13.cast(@test_ean) == {:ok, @test_ean}
|
||||
assert ISN.EAN13.cast(nil) == :error
|
||||
end
|
||||
|
||||
test "load" do
|
||||
assert Isn.EAN13.load(@test_ean) == {:ok, @test_ean}
|
||||
assert ISN.EAN13.load(@test_ean) == {:ok, @test_ean}
|
||||
end
|
||||
|
||||
test "dump" do
|
||||
assert Isn.EAN13.dump(@test_ean) == {:ok, @test_ean}
|
||||
assert ISN.EAN13.dump(@test_ean) == {:ok, @test_ean}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
defmodule Isn.ISBN13Test do
|
||||
defmodule ISN.ISBN13Test do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
@test_isbn "978-1-937785-58-1"
|
||||
|
||||
test "cast" do
|
||||
assert Isn.ISBN13.cast(@test_isbn) == {:ok, @test_isbn}
|
||||
assert Isn.ISBN13.cast(nil) == :error
|
||||
assert ISN.ISBN13.cast(@test_isbn) == {:ok, @test_isbn}
|
||||
assert ISN.ISBN13.cast(nil) == :error
|
||||
end
|
||||
|
||||
test "load" do
|
||||
assert Isn.ISBN13.load(@test_isbn) == {:ok, @test_isbn}
|
||||
assert ISN.ISBN13.load(@test_isbn) == {:ok, @test_isbn}
|
||||
end
|
||||
|
||||
test "dump" do
|
||||
assert Isn.ISBN13.dump(@test_isbn) == {:ok, @test_isbn}
|
||||
assert ISN.ISBN13.dump(@test_isbn) == {:ok, @test_isbn}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
defmodule Isn.ISBNTest do
|
||||
defmodule ISN.ISBNTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
@test_isbn "1-937785-58-0"
|
||||
|
||||
test "cast" do
|
||||
assert Isn.ISBN.cast(@test_isbn) == {:ok, @test_isbn}
|
||||
assert Isn.ISBN.cast(nil) == :error
|
||||
assert ISN.ISBN.cast(@test_isbn) == {:ok, @test_isbn}
|
||||
assert ISN.ISBN.cast(nil) == :error
|
||||
end
|
||||
|
||||
test "load" do
|
||||
assert Isn.ISBN.load(@test_isbn) == {:ok, @test_isbn}
|
||||
assert ISN.ISBN.load(@test_isbn) == {:ok, @test_isbn}
|
||||
end
|
||||
|
||||
test "dump" do
|
||||
assert Isn.ISBN.dump(@test_isbn) == {:ok, @test_isbn}
|
||||
assert ISN.ISBN.dump(@test_isbn) == {:ok, @test_isbn}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
defmodule Isn.ISMN13Test do
|
||||
defmodule ISN.ISMN13Test do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
@test_ismn "979-0-060-11561-5"
|
||||
|
||||
test "cast" do
|
||||
assert Isn.ISMN13.cast(@test_ismn) == {:ok, @test_ismn}
|
||||
assert Isn.ISMN13.cast(nil) == :error
|
||||
assert ISN.ISMN13.cast(@test_ismn) == {:ok, @test_ismn}
|
||||
assert ISN.ISMN13.cast(nil) == :error
|
||||
end
|
||||
|
||||
test "load" do
|
||||
assert Isn.ISMN13.load(@test_ismn) == {:ok, @test_ismn}
|
||||
assert ISN.ISMN13.load(@test_ismn) == {:ok, @test_ismn}
|
||||
end
|
||||
|
||||
test "dump" do
|
||||
assert Isn.ISMN13.dump(@test_ismn) == {:ok, @test_ismn}
|
||||
assert ISN.ISMN13.dump(@test_ismn) == {:ok, @test_ismn}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
defmodule Isn.ISMNTest do
|
||||
defmodule ISN.ISMNTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
@test_ismn "M-060-11561-5"
|
||||
|
||||
test "cast" do
|
||||
assert Isn.ISMN.cast(@test_ismn) == {:ok, @test_ismn}
|
||||
assert Isn.ISMN.cast(nil) == :error
|
||||
assert ISN.ISMN.cast(@test_ismn) == {:ok, @test_ismn}
|
||||
assert ISN.ISMN.cast(nil) == :error
|
||||
end
|
||||
|
||||
test "load" do
|
||||
assert Isn.ISMN.load(@test_ismn) == {:ok, @test_ismn}
|
||||
assert ISN.ISMN.load(@test_ismn) == {:ok, @test_ismn}
|
||||
end
|
||||
|
||||
test "dump" do
|
||||
assert Isn.ISMN.dump(@test_ismn) == {:ok, @test_ismn}
|
||||
assert ISN.ISMN.dump(@test_ismn) == {:ok, @test_ismn}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
defmodule Isn.ISSN13Test do
|
||||
defmodule ISN.ISSN13Test do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
@test_issn "977-1436-452-00-8"
|
||||
|
||||
test "cast" do
|
||||
assert Isn.ISSN13.cast(@test_issn) == {:ok, @test_issn}
|
||||
assert Isn.ISSN13.cast(nil) == :error
|
||||
assert ISN.ISSN13.cast(@test_issn) == {:ok, @test_issn}
|
||||
assert ISN.ISSN13.cast(nil) == :error
|
||||
end
|
||||
|
||||
test "load" do
|
||||
assert Isn.ISSN13.load(@test_issn) == {:ok, @test_issn}
|
||||
assert ISN.ISSN13.load(@test_issn) == {:ok, @test_issn}
|
||||
end
|
||||
|
||||
test "dump" do
|
||||
assert Isn.ISSN13.dump(@test_issn) == {:ok, @test_issn}
|
||||
assert ISN.ISSN13.dump(@test_issn) == {:ok, @test_issn}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
defmodule Isn.ISSNTest do
|
||||
defmodule ISN.ISSNTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
@test_issn "1436-4522"
|
||||
|
||||
test "cast" do
|
||||
assert Isn.ISSN.cast(@test_issn) == {:ok, @test_issn}
|
||||
assert Isn.ISSN.cast(nil) == :error
|
||||
assert ISN.ISSN.cast(@test_issn) == {:ok, @test_issn}
|
||||
assert ISN.ISSN.cast(nil) == :error
|
||||
end
|
||||
|
||||
test "load" do
|
||||
assert Isn.ISSN.load(@test_issn) == {:ok, @test_issn}
|
||||
assert ISN.ISSN.load(@test_issn) == {:ok, @test_issn}
|
||||
end
|
||||
|
||||
test "dump" do
|
||||
assert Isn.ISSN.dump(@test_issn) == {:ok, @test_issn}
|
||||
assert ISN.ISSN.dump(@test_issn) == {:ok, @test_issn}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
defmodule Isn.UPCTest do
|
||||
defmodule ISN.UPCTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
@test_upc "220356483481"
|
||||
|
||||
test "cast" do
|
||||
assert Isn.UPC.cast(@test_upc) == {:ok, @test_upc}
|
||||
assert Isn.UPC.cast(nil) == :error
|
||||
assert ISN.UPC.cast(@test_upc) == {:ok, @test_upc}
|
||||
assert ISN.UPC.cast(nil) == :error
|
||||
end
|
||||
|
||||
test "load" do
|
||||
assert Isn.UPC.load(@test_upc) == {:ok, @test_upc}
|
||||
assert ISN.UPC.load(@test_upc) == {:ok, @test_upc}
|
||||
end
|
||||
|
||||
test "dump" do
|
||||
assert Isn.UPC.dump(@test_upc) == {:ok, @test_upc}
|
||||
assert ISN.UPC.dump(@test_upc) == {:ok, @test_upc}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
defmodule IsnTest do
|
||||
defmodule ISNTest do
|
||||
use ExUnit.Case, async: true
|
||||
import Isn.TestHelper
|
||||
import ISN.TestHelper
|
||||
alias Postgrex.Connection, 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
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ ExUnit.start()
|
|||
# {:ok, pid} = Postgrex.Connection.start_link(conn_options)
|
||||
# Postgrex.Connection.query!(pid, "CREATE EXTENSION isn;", [])
|
||||
|
||||
defmodule Isn.TestHelper do
|
||||
defmodule ISN.TestHelper do
|
||||
def conn_options do
|
||||
db_options = [
|
||||
sync_connect: true,
|
||||
|
|
@ -47,12 +47,12 @@ 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.Connection.start_link(db_options)
|
||||
|
||||
Postgrex.Connection.query!(pid, "DROP DATABASE IF EXISTS isn_test;", [])
|
||||
Postgrex.Connection.query!(pid, "CREATE DATABASE isn_test;", [])
|
||||
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.stop(pid)
|
||||
|
|
|
|||
Loading…
Reference in New Issue