diff options
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods/deprecated_underscore_read.rb')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/deprecated_underscore_read.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/deprecated_underscore_read.rb b/activerecord/lib/active_record/attribute_methods/deprecated_underscore_read.rb new file mode 100644 index 0000000000..0eb0db65b1 --- /dev/null +++ b/activerecord/lib/active_record/attribute_methods/deprecated_underscore_read.rb @@ -0,0 +1,32 @@ +require 'active_support/concern' +require 'active_support/deprecation' + +module ActiveRecord + module AttributeMethods + module DeprecatedUnderscoreRead + extend ActiveSupport::Concern + + included do + attribute_method_prefix "_" + end + + module ClassMethods + protected + + def define_method__attribute(attr_name) + # Do nothing, let it hit method missing instead. + end + end + + protected + + def _attribute(attr_name) + ActiveSupport::Deprecation.warn( + "You have called '_#{attr_name}'. This is deprecated. Please use " \ + "either '#{attr_name}' or read_attribute('#{attr_name}')." + ) + read_attribute(attr_name) + end + end + end +end |