zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

id.ex (2492B)


      1 # Zenflows is designed to implement the Valueflows vocabulary,
      2 # written and maintained by srfsh <info@dyne.org>.
      3 # Copyright (C) 2021-2023 Dyne.org foundation <foundation@dyne.org>.
      4 #
      5 # This program is free software: you can redistribute it and/or modify
      6 # it under the terms of the GNU Affero General Public License as published by
      7 # the Free Software Foundation, either version 3 of the License, or
      8 # (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU Affero General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU Affero General Public License
     16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     17 
     18 defmodule Zenflows.VF.Action.ID do
     19 @moduledoc """
     20 Custom Ecto type for Action ID definitions in schemas.
     21 """
     22 
     23 use Ecto.Type
     24 
     25 @type t() :: String.t()
     26 
     27 @spec values() :: [t(), ...]
     28 def values() do
     29 	~w[
     30 		produce use consume cite work
     31 		pickup dropoff accept modify
     32 		combine separate move transfer
     33 		transferAllRights
     34 		transferCustody
     35 		raise lower
     36 	]
     37 end
     38 
     39 @impl true
     40 def type(), do: :string
     41 
     42 @impl true
     43 def cast("produce" = x),             do: {:ok, x}
     44 def cast("use" = x),                 do: {:ok, x}
     45 def cast("consume" = x),             do: {:ok, x}
     46 def cast("cite" = x),                do: {:ok, x}
     47 def cast("work" = x),                do: {:ok, x}
     48 def cast("deliverService" = x),      do: {:ok, x}
     49 def cast("deliver-service"),         do: {:ok, "deliverService"}
     50 def cast("pickup" = x),              do: {:ok, x}
     51 def cast("dropoff" = x),             do: {:ok, x}
     52 def cast("accept" = x),              do: {:ok, x}
     53 def cast("modify" = x),              do: {:ok, x}
     54 def cast("combine" = x),             do: {:ok, x}
     55 def cast("separate" = x),            do: {:ok, x}
     56 def cast("transfer" = x),            do: {:ok, x}
     57 def cast("move" = x),                do: {:ok, x}
     58 def cast("raise" = x),               do: {:ok, x}
     59 def cast("lower" = x),               do: {:ok, x}
     60 def cast("transferAllRights" = x),   do: {:ok, x}
     61 def cast("transferCustody" = x),     do: {:ok, x}
     62 def cast("transfer-all-rights"),     do: {:ok, "transferAllRights"}
     63 def cast("transfer-custody"),        do: {:ok, "transferCustody"}
     64 def cast(x), do: {:error, message: "unknown action id #{inspect(x)}"}
     65 
     66 @impl true
     67 def dump(x), do: cast(x)
     68 
     69 @impl true
     70 def load(x), do: cast(x)
     71 end