WIP
This commit is contained in:
commit
41c9c85cd6
|
|
@ -0,0 +1,5 @@
|
|||
/_build
|
||||
/cover
|
||||
/deps
|
||||
erl_crash.dump
|
||||
*.ez
|
||||
|
|
@ -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"
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
defmodule Isn.ISBN13 do
|
||||
use Isn.Base, :isbn13
|
||||
end
|
||||
|
|
@ -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
|
||||
|
|
@ -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"}}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
defmodule IsnTest do
|
||||
use ExUnit.Case
|
||||
doctest Isn
|
||||
|
||||
test "the truth" do
|
||||
assert 1 + 1 == 2
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
ExUnit.start()
|
||||
Loading…
Reference in New Issue