lib/enum_attr.rb in enum_attr-0.0.5 vs lib/enum_attr.rb in enum_attr-0.0.6
- old
+ new
@@ -33,14 +33,20 @@
const_set("#{attr.upcase}_#{enum[2].upcase}", enum[1] )
# TODO: how to judge if there is active_record 3 gem here?
scope "#{attr}_#{enum[2]}".to_sym, where("#{attr}=#{enum[1]}")
- # TODO define_method such as "stauts_origin?"
- define_method "#{attr}_#{enum[2]}?" do
- attr == enum[1]
- end
+ # # TODO define_method such as "stauts_origin?"
+ # why does this get error result?
+ # define_method "#{attr}_#{enum[2]}?" do
+ # attr == enum[1]
+ # end
+ class_eval(%Q{
+ def #{attr}_#{enum[2]}?
+ #{attr} == #{enum[1]}
+ end
+ })
end # end: enums.each
self.class_eval(%Q{
@@ -53,11 +59,14 @@
end
def #{attr}_name
ENUMS_#{attr.upcase}.find{|option| option[1] == #{attr}}[0] unless #{attr}.nil?
end
- })
+
+})
end
+
+
end
end
Object.send :include, EnumAttr::Mixin
\ No newline at end of file