diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2015-07-23 14:27:09 +0200 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2015-07-23 14:27:09 +0200 |
commit | ad5c1a39346d559f26c11c2399117491a3d81c0b (patch) | |
tree | 712436e163909b27b36119c0cdc5566942289674 /activerecord | |
parent | 0e189cb3df7899bd99697a40b9e5f6316299ac04 (diff) | |
download | rails-ad5c1a39346d559f26c11c2399117491a3d81c0b.tar.gz rails-ad5c1a39346d559f26c11c2399117491a3d81c0b.tar.bz2 rails-ad5c1a39346d559f26c11c2399117491a3d81c0b.zip |
Rename the enum_{prefix,suffix} options to _{prefix,suffix}
This makes it more clear that they are reserved keywords and also it
seems less redundant as the line already starts with the call to the
`enum` method.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/enum.rb | 20 | ||||
-rw-r--r-- | activerecord/test/models/book.rb | 8 |
3 files changed, 15 insertions, 15 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index fb64156b78..8676f95d6d 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -170,7 +170,7 @@ *Aster Ryan* -* Add `:enum_prefix`/`:enum_suffix` option to `enum` definition. +* Add `:_prefix` and `:_suffix` options to `enum` definition. Fixes #17511, #17415. diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index c0d9d9c1c8..9c9307df15 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -75,22 +75,22 @@ module ActiveRecord # # Conversation.where("status <> ?", Conversation.statuses[:archived]) # - # You can use the +:enum_prefix+ or +:enum_suffix+ options when you need - # to define multiple enums with same values. If the passed value is +true+, - # the methods are prefixed/suffixed with the name of the enum. + # You can use the +:_prefix+ or +:_suffix+ options when you need to define + # multiple enums with same values. If the passed value is +true+, the methods + # are prefixed/suffixed with the name of the enum. # # class Invoice < ActiveRecord::Base - # enum verification: [:done, :fail], enum_prefix: true + # enum verification: [:done, :fail], _prefix: true # end # - # It is also possible to supply a custom prefix. + # It is also possible to supply a custom value: # # class Invoice < ActiveRecord::Base - # enum verification: [:done, :fail], enum_prefix: :verification_status + # enum verification: [:done, :fail], _prefix: :verification_status # end # - # Note that <tt>:enum_prefix</tt>/<tt>:enum_suffix</tt> are reserved keywords - # and can not be used as an enum name. + # Note that <tt>:_prefix</tt>/<tt>:_suffix</tt> are reserved keywords and can + # not be used as enum names. module Enum def self.extended(base) # :nodoc: @@ -137,8 +137,8 @@ module ActiveRecord def enum(definitions) klass = self - enum_prefix = definitions.delete(:enum_prefix) - enum_suffix = definitions.delete(:enum_suffix) + enum_prefix = definitions.delete(:_prefix) + enum_suffix = definitions.delete(:_suffix) definitions.each do |name, values| # statuses = { } enum_values = ActiveSupport::HashWithIndifferentAccess.new diff --git a/activerecord/test/models/book.rb b/activerecord/test/models/book.rb index 24bfe47bbf..1927191393 100644 --- a/activerecord/test/models/book.rb +++ b/activerecord/test/models/book.rb @@ -10,10 +10,10 @@ class Book < ActiveRecord::Base enum status: [:proposed, :written, :published] enum read_status: {unread: 0, reading: 2, read: 3} enum nullable_status: [:single, :married] - enum language: [:english, :spanish, :french], enum_prefix: :in - enum author_visibility: [:visible, :invisible], enum_prefix: true - enum illustrator_visibility: [:visible, :invisible], enum_prefix: true - enum font_size: [:small, :medium, :large], enum_prefix: :with, enum_suffix: true + enum language: [:english, :spanish, :french], _prefix: :in + enum author_visibility: [:visible, :invisible], _prefix: true + enum illustrator_visibility: [:visible, :invisible], _prefix: true + enum font_size: [:small, :medium, :large], _prefix: :with, _suffix: true def published! super |