lib/degu/has_enum.rb in degu-0.2.0 vs lib/degu/has_enum.rb in degu-0.3.0
- old
+ new
@@ -66,9 +66,15 @@
define_method("#{enum_name}_has_changed?") do
!!@enum_changed
end
+ enum_class.each do |enum|
+ define_method("#{enum_name}_#{enum.underscored_name}?") do
+ __send__(enum_name.to_sym) == enum
+ end
+ end
+
define_method("#{enum_column}_check_for_valid_type_of_enum") do
return true if self[enum_column].nil? || self[enum_column].to_s.empty?
unless enum_class[self[enum_column]].present?
self.errors.add(enum_column.to_sym, "Wrong type '#{self[enum_column]}' for enum '#{enum_name}'")
return false