Carl Hörberg on development

The Ruby ORM DataMapper as a Enum property which is really handy, but you often want to list the available options in for example a form. Unfortunately it's not well documented, but this gist shows you how:

1 2 3 4 5 6 7 8
class Entity
include DataMapper::Resource
property :enum_property, Enum[:a, :b, :c]
Entity.enum_property.options[:flags] #=> [:a, :b, :c]
# or
Entity.enum_property.flag_option.values #=> [:a, :b, :c]
view raw gistfile1.rb hosted with ❤ by GitHub

blog comments powered by Disqus