diff --git a/lib/attr_enumerator.rb b/lib/attr_enumerator.rb index 4068401..6faf4c1 100644 --- a/lib/attr_enumerator.rb +++ b/lib/attr_enumerator.rb @@ -9,14 +9,14 @@ def attr_enumerator(attribute, choices, options = {}) constant = options.delete(:constant) || attribute.to_s.pluralize.upcase prefix = options[:prefix] ? options.delete(:prefix).to_s + '_' : '' options[:message] ||= :invalid - + const_set(constant, choices).freeze validates_inclusion_of attribute, options.merge(:in => choices) choices.each do |choice| choice_string = prefix + choice.to_s.underscore.parameterize('_') define_method(choice_string + '?') { send(attribute) == choice } - scope choice_string, where(attribute => choice) if respond_to? :scope + scope choice_string, lambda { where(attribute => choice) } if respond_to? :scope end end end