Skip to content

Commit

Permalink
Fix failures related to enum changes
Browse files Browse the repository at this point in the history
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
carlosantoniodasilva committed Nov 4, 2013
1 parent 28dea53 commit 6d540d1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions activerecord/lib/active_record/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 6d540d1

Please sign in to comment.