Module: RailsAdminAutoEnum::ActiveRecord::RailsAdminEnum

Defined in:
lib/rails_admin-auto-enum/rails_admin.rb

Instance Method Summary collapse

Instance Method Details

#enum(definitions) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rails_admin-auto-enum/rails_admin.rb', line 14

def enum(definitions)
  super

  definitions.each do |name, values|
    define_method("#{name}_enum") { self.class.send(name.to_s.pluralize).to_a }

    define_method("#{name}=") do |value|
      super value.kind_of?(String) && value.to_i.to_s == value ? value.to_i : value
    end
  end
end