diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-11-04 13:40:16 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-11-04 13:40:16 -0200 |
commit | 6d540d135f8a542bbcbf0b2fa5da39f3d572d5f0 (patch) | |
tree | 248d9c2e508f8d2aafb2462d4dd5beab6dccb17c /activerecord | |
parent | 28dea539e1c471f3d12b85afcd92214df7f34aeb (diff) | |
download | rails-6d540d135f8a542bbcbf0b2fa5da39f3d572d5f0.tar.gz rails-6d540d135f8a542bbcbf0b2fa5da39f3d572d5f0.tar.bz2 rails-6d540d135f8a542bbcbf0b2fa5da39f3d572d5f0.zip |
Fix failures related to enum changes
Commit 6e4a810f51b9ed2468b92247ef5568cc9d6dbcc0 changed the implementation
from class_eval to define_method, but missed the access to the constant
versus the access to the constant name.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/enum.rb | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index 3baaea7268..f22ff2c472 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -36,25 +36,23 @@ module ActiveRecord module Enum def enum(definitions) definitions.each do |name, values| - const_name = name.to_s.upcase - # DIRECTION = { } - const_set const_name, {} + const = const_set name.to_s.upcase, {} # def direction=(value) self[:direction] = DIRECTION[value] end define_method "#{name}=" do |value| - self[:"#{name}"] = const_name[value] + self[:"#{name}"] = const[value] end # def direction() DIRECTION.key self[:direction] end define_method name do - const_name.key self[:"#{name}"] + const.key self[:"#{name}"] end pairs = values.respond_to?(:each_pair) ? values.each_pair : values.each_with_index pairs.each do |value, i| # DIRECTION[:incoming] = 0 - const_get(const_name)[value] = i + const[value] = i # scope :incoming, -> { where direction: 0 } scope value, -> { where name => i } |