Module: ActiveEnum::MixIn

Defined in:
lib/sga_enum.rb

Instance Method Summary collapse

Instance Method Details

#enum_attr(attr, enums, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/sga_enum.rb', line 3

def enum_attr attr, enums, options={}
  attr = attr.to_s
  self.class_eval <<-EOF
    ENUMS_#{attr.upcase} = enums
    options.merge! :in => enums.map{|e| e[1]}
    validates_inclusion_of attr, options
    def #{attr}_name
      ENUMS_#{attr.upcase}.find{|op| op[1] == #{attr}}[0] unless #{attr}.nil?
    end
  EOF
end