Module: Enumerations::ClassMethods

Defined in:
lib/enumerations.rb

Instance Method Summary collapse

Instance Method Details

#enumeration(name, options = {}) ⇒ Object

Create an enumeration for the symbol name. Options include foreign_key attribute and class_name

Example:

 class User < ActiveRecord::Base
   enumeration :role
 end

user.role => #<Enumerations::Value: @base=Role, @symbol=:admin...>

user.role = Role.staff


33
34
35
36
37
# File 'lib/enumerations.rb', line 33

def enumeration(name, options = {})
  reflection = Reflection.new(name, options)

  add_enumeration(reflection)
end

#reflect_on_all_enumerationsObject

Output all the enumerations that this model has defined Returns an array of Reflection objects for all the enumerations in the class.

Example:

User.reflect_on_all_enumerations => # [
   #<Enumerations::Reflection: @name=:role...>,
   #<Enumerations::Reflection: @name=:status...>
]


50
51
52
# File 'lib/enumerations.rb', line 50

def reflect_on_all_enumerations
  _enumerations
end