aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
diff options
context:
space:
mode:
authorYoshiyuki Kinjo <kinjo@bita.jp>2018-10-09 16:14:51 +0900
committerYoshiyuki Kinjo <yskkin@gmail.com>2018-10-19 14:16:03 +0900
commit32b03b46150b0161eba2321ccac7678511e3d58e (patch)
tree188dab7661dc55be022c851c878de7d68c208e20 /activerecord/lib/active_record/attribute_methods.rb
parent99c87ad2474d5c5b6e52ceac34c3cf9f9cb57f9f (diff)
downloadrails-32b03b46150b0161eba2321ccac7678511e3d58e.tar.gz
rails-32b03b46150b0161eba2321ccac7678511e3d58e.tar.bz2
rails-32b03b46150b0161eba2321ccac7678511e3d58e.zip
Implement AR#inspect using ParamterFilter.
AR instance support `filter_parameters` since #33756. Though Regex or Proc is valid as `filter_parameters`, they are not supported as AR#inspect. I also add :mask option and #filter_params to `ActiveSupport::ParameterFilter#new` to implement this.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb19
1 files changed, 11 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 3c785180e1..1581490f16 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -336,14 +336,7 @@ module ActiveRecord
# # => "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]"
def attribute_for_inspect(attr_name)
value = read_attribute(attr_name)
-
- if value.is_a?(String) && value.length > 50
- "#{value[0, 50]}...".inspect
- elsif value.is_a?(Date) || value.is_a?(Time)
- %("#{value.to_s(:db)}")
- else
- value.inspect
- end
+ format_for_inspect(value)
end
# Returns +true+ if the specified +attribute+ has been set by the user or by a
@@ -463,6 +456,16 @@ module ActiveRecord
end
end
+ def format_for_inspect(value)
+ if value.is_a?(String) && value.length > 50
+ "#{value[0, 50]}...".inspect
+ elsif value.is_a?(Date) || value.is_a?(Time)
+ %("#{value.to_s(:db)}")
+ else
+ value.inspect
+ end
+ end
+
def readonly_attribute?(name)
self.class.readonly_attributes.include?(name)
end