提交 6d540d13 编写于 作者: C Carlos Antonio da Silva

Fix failures related to enum changes

Commit 6e4a810f changed the implementation
from class_eval to define_method, but missed the access to the constant
versus the access to the constant name.
上级 28dea539
......@@ -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 }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册