diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-11-04 15:55:29 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-11-04 15:55:29 -0800 |
commit | 9f8762f1d5e84472b1cae16b063fc79d1de15963 (patch) | |
tree | 8beb6791a5a96f6cf1dd0aefaa4e6811fc9ba383 | |
parent | 238ee10c41af267d6c931b9eff4cdad674911a23 (diff) | |
download | rails-9f8762f1d5e84472b1cae16b063fc79d1de15963.tar.gz rails-9f8762f1d5e84472b1cae16b063fc79d1de15963.tar.bz2 rails-9f8762f1d5e84472b1cae16b063fc79d1de15963.zip |
The enum value constant isn't used, so rm it for now.
-rw-r--r-- | activerecord/lib/active_record/enum.rb | 24 | ||||
-rw-r--r-- | activerecord/test/cases/enum_test.rb | 10 |
2 files changed, 7 insertions, 27 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index 72373d5d5a..da6bc87950 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -36,37 +36,27 @@ module ActiveRecord module Enum def enum(definitions) definitions.each do |name, values| - # DIRECTION = { } - const = const_set name.to_s.upcase, {} - name = name.to_sym + enum_values = {} + name = name.to_sym # def direction=(value) self[:direction] = DIRECTION[value] end - define_method "#{name}=" do |value| - self[name] = const[value] - end + define_method("#{name}=") { |value| self[name] = enum_values[value] } # def direction() DIRECTION.key self[:direction] end - define_method name do - const.key self[name] - 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| - # DIRECTION[:incoming] = 0 - const[value] = i + enum_values[value] = i # scope :incoming, -> { where direction: 0 } scope value, -> { where name => i } # def incoming?() direction == 0 end - define_method "#{value}?" do - self[name] == i - end + define_method("#{value}?") { self[name] == i } # def incoming! update! direction: :incoming end - define_method "#{value}!" do - update! name => value.to_sym - end + define_method("#{value}!") { update! name => value.to_sym } end end end diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb index dc814227f0..8eb82ead3c 100644 --- a/activerecord/test/cases/enum_test.rb +++ b/activerecord/test/cases/enum_test.rb @@ -35,14 +35,4 @@ class EnumTest < ActiveRecord::TestCase @book.update! status: :written assert @book.written? end - - test "constant" do - assert_equal 0, Book::STATUS[:proposed] - assert_equal 1, Book::STATUS[:written] - assert_equal 2, Book::STATUS[:published] - - assert_equal 0, Book::READ_STATUS[:unread] - assert_equal 2, Book::READ_STATUS[:reading] - assert_equal 3, Book::READ_STATUS[:read] - end end |