Module: SimpleEnum::Mongoid::ClassMethods

Defined in:
lib/simple_enum/mongoid.rb

Instance Method Summary collapse

Instance Method Details

#as_enum(name, values, options = {}) ⇒ Object

Wrap method chain to create mongoid field and additional column options



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/simple_enum/mongoid.rb', line 35

def as_enum(name, values, options = {})
  field_options = options.delete(:field)
  enum = super
  accessor = send("#{name.to_s.pluralize}_accessor")

  unless field_options === false
    field_options ||= SimpleEnum.field
    field(accessor.source, field_options) if field_options
  end

  enum
end