ecto_enum icon indicating copy to clipboard operation
ecto_enum copied to clipboard

Sugar! to get backing value directly

Open almozavr opened this issue 6 years ago • 1 comments

Issue

dump/1 returns {:ok, integer} while we'd lite to access value directly (e.g. for views adapters)

Proposal

dump!/1 to return integer or to raise exception

almozavr avatar Sep 03 '18 14:09 almozavr

@almozavr, you can use __enum__map__/0 to get kw list with keys-values. So suppose you have a type MyApp.MyEnum which contains a key :key, then you can get its backing value like this:

MyApp.MyEnum.__enum_map__[:key]

On the other side I don't see why would you need this value in views or adapters? What's exactly the case?

yunmikun2 avatar Oct 01 '20 09:10 yunmikun2