Permalink
Browse files

Fix failures related to enum changes

Commit 6e4a810 changed the implementation
from class_eval to define_method, but missed the access to the constant
versus the access to the constant name.
  • Loading branch information...
1 parent 28dea53 commit 6d540d135f8a542bbcbf0b2fa5da39f3d572d5f0 @carlosantoniodasilva carlosantoniodasilva committed Nov 4, 2013
Showing with 4 additions and 6 deletions.
  1. +4 −6 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 }

0 comments on commit 6d540d1

Please sign in to comment.