Permalink
Browse files

more bugfixes

  • Loading branch information...
1 parent 7219f64 commit 8149874fd918aebf8900133c22cc2fd0220e32e1 Aditya Sanghi committed Sep 26, 2010
Showing with 5 additions and 4 deletions.
  1. +5 −4 lib/enumlogic.rb
View
@@ -34,9 +34,10 @@ def enum(field, values, options = {})
constant_name = options[:constant] || field.to_s.pluralize.upcase
const_set constant_name, values_array unless const_defined?(constant_name)
- new_hash = {}
- values_hash.each { |key, text| new_hash[text] = key }
- (class << self; self; end).send(:define_method, "#{field}_options") { new_hash }
+ (class << self; self; end).send(:define_method, "#{field}_options") do
+ new_hash = {}
+ values_hash.each { |key, text| new_hash[text] = key }
+ end
define_method("#{field}_key") do
value = send(field)
@@ -58,7 +59,7 @@ def enum(field, values, options = {})
end
end
- validates_inclusion_of field, :in => values_array, :message => options[:message], :allow_nil => options[:allow_nil], :if => options[:if]
+ validates field, :inclusion => {:in => values_array}, :allow_blank => options[:allow_blank]
end
def enum?(name)

0 comments on commit 8149874

Please sign in to comment.