Permalink
Browse files

Use the same enum definition in the docs and in the comments [ci skip]

  • Loading branch information...
1 parent cbd4bc8 commit 7432d32f527f9a06ed51f576985987a1f87c5c78 @chancancode chancancode committed Dec 22, 2013
Showing with 6 additions and 6 deletions.
  1. +6 −6 activerecord/lib/active_record/enum.rb
@@ -55,33 +55,33 @@ module Enum
def enum(definitions)
klass = self
definitions.each do |name, values|
- # DIRECTION = { }
+ # STATUS = { }
enum_values = _enum_methods_module.const_set name.to_s.upcase, ActiveSupport::HashWithIndifferentAccess.new
name = name.to_sym
_enum_methods_module.module_eval do
- # def direction=(value) self[:direction] = DIRECTION[value] end
+ # def status=(value) self[:status] = STATUS[value] end
define_method("#{name}=") { |value|
unless enum_values.has_key?(value)
raise ArgumentError, "'#{value}' is not a valid #{name}"
end
self[name] = enum_values[value]
}
- # def direction() DIRECTION.key self[:direction] end
+ # def status() STATUS.key self[:status] end
define_method(name) { enum_values.key self[name] }
pairs = values.respond_to?(:each_pair) ? values.each_pair : values.each_with_index
pairs.each do |value, i|
enum_values[value] = i
- # scope :incoming, -> { where direction: 0 }
+ # scope :active, -> { where status: 0 }
klass.scope value, -> { klass.where name => i }
- # def incoming?() direction == 0 end
+ # def active?() status == 0 end
define_method("#{value}?") { self[name] == i }
- # def incoming! update! direction: :incoming end
+ # def active! update! status: :active end
define_method("#{value}!") { update! name => value }
end
end

0 comments on commit 7432d32

Please sign in to comment.