From 510601ce8e6f95b47646e61d6e366245fbb5a329 Mon Sep 17 00:00:00 2001 From: Jan Bernacki Date: Sat, 26 Oct 2013 18:01:37 +0400 Subject: short arrays in inspect --- activerecord/lib/active_record/attribute_methods.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/attribute_methods.rb') diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 43419efc75..3924eec872 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -245,9 +245,10 @@ module ActiveRecord # Returns an #inspect-like string for the value of the # attribute +attr_name+. String attributes are truncated upto 50 - # characters, and Date and Time attributes are returned in the - # :db format. Other attributes return the value of - # #inspect without modification. + # characters, Date and Time attributes are returned in the + # :db format, Array attributes are truncated upto 10 values. + # Other attributes return the value of #inspect without + # modification. # # person = Person.create!(name: 'David Heinemeier Hansson ' * 3) # @@ -256,6 +257,9 @@ module ActiveRecord # # person.attribute_for_inspect(:created_at) # # => "\"2012-10-22 00:15:07\"" + # + # person.attribute_for_inspect(:tag_ids) + # # => "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...]" def attribute_for_inspect(attr_name) value = read_attribute(attr_name) @@ -263,6 +267,9 @@ module ActiveRecord "#{value[0, 50]}...".inspect elsif value.is_a?(Date) || value.is_a?(Time) %("#{value.to_s(:db)}") + elsif value.is_a?(Array) && value.size > 10 + inspected = value.first(10).inspect + %(#{inspected[0...-1]}, ...]) else value.inspect end -- cgit v1.2.3