lib/enum_attr.rb in enum_attr-0.0.4 vs lib/enum_attr.rb in enum_attr-0.0.5

- old
+ new

@@ -1,5 +1,7 @@ +# encoding: utf-8 + module EnumAttr module Mixin # for model Contract: # enum_attr :status, [['新建', 0, "origin"], ['整理中', 1, "collecting"], ["已上传", 2, "uploaded"]] # It generates these code for you: @@ -43,9 +45,13 @@ self.class_eval(%Q{ ENUMS_#{attr.upcase} = enums.collect{|item| [item[0], item[1]]} validates_inclusion_of attr, :in => enums.map{|e| e[1].to_i}, :allow_nil => true + +def self.#{attr}_name_by(arg) + ENUMS_#{attr.upcase}.find{|option| option[1] == arg }[0] +end def #{attr}_name ENUMS_#{attr.upcase}.find{|option| option[1] == #{attr}}[0] unless #{attr}.nil? end }) \ No newline at end of file