Module: Wijet::SimpleEnumerations::ClassMethods

Defined in:
lib/simple_enumerations/simple_enumerations.rb

Instance Method Summary collapse

Instance Method Details

#has_enumerated(name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_enumerations/simple_enumerations.rb', line 8

def has_enumerated(name)
  EnumerationString::Enumeration.setup

  name = name.to_s

  define_method("#{name}=") do |value|
    value = value.to_s
    unless Enumeration[name].include?(value) or value.blank?
      raise ArgumentError, "'#{value}' is not a value of enumeration '#{name}'"
    end
    write_attribute(name, value)
  end

  define_method(name) do
    EnumerationString::Enumeration.new(attributes[name])
  end
end