This commit is contained in:
Martin Frost 2015-05-05 22:15:40 +02:00
commit 41c9c85cd6
10 changed files with 137 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/_build
/cover
/deps
erl_crash.dump
*.ez

4
README.md Normal file
View File

@ -0,0 +1,4 @@
Isn
===
** TODO: Add description **

26
config/config.exs Normal file
View File

@ -0,0 +1,26 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for third-
# party users, it should be done in your mix.exs file.
# Sample configuration:
#
# config :logger,
# level: :info
#
# config :logger, :console,
# format: "$date $time [$level] $metadata$message\n",
# metadata: [:user_id]
# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"

20
lib/isn/base.ex Normal file
View File

@ -0,0 +1,20 @@
defmodule Isn.Base do
defmacro __using__(type) do
quote bind_quoted: [type: type] do
# @behaviour Ecto.Type
#
@moduledoc """
Definition for the #{@type} module.
"""
def type,
do: type
defdelegate blank?, to: Ecto.Type
def cast(isn), do: {:ok, to_string(isn)}
def load(isn), do: {:ok, to_string(isn)}
def dump(isn), do: {:ok, to_string(isn)}
end
end
end

21
lib/isn/extension.ex Normal file
View File

@ -0,0 +1,21 @@
defmodule Isn.Extension do
alias Postgrex.TypeInfo
@behaviour Postgrex.Extension
@isn ~w(ean13 isbn13 ismn13 issn13 isbn ismn issn upc)
def init(parameters, _opts),
do: parameters
def matching(_library),
do: Enum.reduce(@isn, [], fn(t, ack) -> ack ++ [type: t] end)
def format(_),
do: :string
def encode(%TypeInfo{type: type}, binary, _types, _opts) when type in @isn,
do: binary
def decode(%TypeInfo{type: type}, binary, _types, _opts) when type in @isn,
do: binary
end

3
lib/isn/isbn13.ex Normal file
View File

@ -0,0 +1,3 @@
defmodule Isn.ISBN13 do
use Isn.Base, :isbn13
end

45
mix.exs Normal file
View File

@ -0,0 +1,45 @@
defmodule Isn.Mixfile do
use Mix.Project
@version "0.0.1"
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"]
]
end
# Configuration for the OTP application
#
# Type `mix help compile.app` for more information
def application do
[]
end
defp description do
"""
Ecto types for the postgreSQL isn extension.
"""
end
defp package do
[contributors: ["Martin Frost"],
licences: ["MIT"],
links: %{"GitHub" => "https://github.com/Frost/isn"}]
end
defp deps do
[{:postgrex, "~> 0.8.1"},
{:ecto, "~> 0.11.0"}]
end
end

4
mix.lock Normal file
View File

@ -0,0 +1,4 @@
%{"decimal": {:hex, :decimal, "1.1.0"},
"ecto": {:hex, :ecto, "0.11.0"},
"poolboy": {:hex, :poolboy, "1.5.1"},
"postgrex": {:hex, :postgrex, "0.8.1"}}

8
test/isn_test.exs Normal file
View File

@ -0,0 +1,8 @@
defmodule IsnTest do
use ExUnit.Case
doctest Isn
test "the truth" do
assert 1 + 1 == 2
end
end

1
test/test_helper.exs Normal file
View File

@ -0,0 +1 @@
ExUnit.start()