Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Created July 19, 2017 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmarreck/27f6ea5d937904f553d90568fb306d2e to your computer and use it in GitHub Desktop.
Save pmarreck/27f6ea5d937904f553d90568fb306d2e to your computer and use it in GitHub Desktop.
trying to use ecto_enum...
defmodule Mpnetwork.EnumMaps do
import EctoEnum
# Housing Class Types
@class_types_int ~w[residential condo co_op hoa rental land com_ind]a
def class_types_int, do: @class_types_int
@class_types_ext ~w[Residential Condo Co-op HOA Rental Land Commercial/Industrial]
# def class_types_ext, do: @class_types_ext
@class_types_int_to_ext_map Enum.zip(@class_types_int, @class_types_ext) |> Map.new
@class_types_ext_to_int_map Enum.zip(@class_types_ext, @class_types_int) |> Map.new
def map_class_type_int_to_ext(k) when is_atom(k), do: @class_types_int_to_ext_map[k]
def map_class_type_int_to_ext(k) when is_binary(k), do: @class_types_int_to_ext_map[String.to_existing_atom(k)]
def map_class_type_ext_to_int(k) when is_binary(k), do: @class_types_ext_to_int_map[k]
defenum ClassTypeEnum, :class_type, @class_types_int
# ...
end
@pmarreck
Copy link
Author

** (FunctionClauseError) no function clause matching in EctoEnum.defenum/3
    expanding macro: EctoEnum.defenum/3
    lib/mpnetwork/ecto_enums.ex:18: Mpnetwork.EnumMaps (module)
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1```

@gjaldon
Copy link

gjaldon commented Jul 20, 2017

@pmarreck what if you change https://github.com/blackswan-ventures/events/pull/19 to:

defenum ClassTypeEnum, :class_type, ~w[residential condo co_op hoa rental land com_ind]a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment