Module: Enumeration::ClassMethods
- Defined in:
- lib/enumerations.rb
Instance Method Summary collapse
-
#enumeration(name, options = {}) ⇒ Object
Create an enumeration for the symbol
name. -
#reflect_on_all_enumerations ⇒ Object
Output all the enumerations that this model has defined Returns an array of Reflection objects for all the enumerations in the class.
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_id = 1
user.role => #<Enumeration::Value:0x007fff45d7ec30 @base=Role, @symbol=:admin...>
user.role = Role.staff
user.role_id => 2
TODO: add documentation for foreign_key and class_name
36 37 38 39 40 41 |
# File 'lib/enumerations.rb', line 36 def enumeration(name, = {}) [:foreign_key] ||= "#{name}_id".to_sym [:class_name] ||= name.to_s.camelize add_enumeration(name, ) end |
#reflect_on_all_enumerations ⇒ Object
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 => # [
#<Enumeration::Reflection:0x007fe894724320 @name=:role...>,
#<Enumeration::Reflection:0x007fe89471d020 @name=:status...>]
53 54 55 |
# File 'lib/enumerations.rb', line 53 def reflect_on_all_enumerations _enumerations end |