Skip to content

Commit

Permalink
use lambda to meet rails4 requirement that scopes respond to call
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Walbran committed May 2, 2013
1 parent a80c697 commit aa38e79
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/attr_enumerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aa38e79

Please sign in to comment.