Method: Enumerations::Base.value
- Defined in:
- lib/enumerations/base.rb
.value(symbol, attributes = {}) ⇒ Object
Adding new value to enumeration
Example:
value :admin, id: 1, name: 'Admin', description: 'Some description...'
Role.find(:admin).name => # "Admin"
Role.find(:admin).description => # "Some description..."
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/enumerations/base.rb', line 27 def self.value(symbol, attributes = {}) validate_symbol_and_primary_key(symbol, attributes) self._values = _values.merge(symbol => new(symbol, attributes)) # Adds name base finder methods # # Example: # # Role.admin => #<Enumerations::Value: @base=Role, @symbol=:admin...> # Role.staff => #<Enumerations::Value: @base=Role, @symbol=:staff...> # singleton_class.send(:define_method, symbol) do find(symbol) end end |