@@ -103,7 +103,19 @@ def self.configurations
103
103
104
104
class_attribute :shard_selector , instance_accessor : false , default : nil
105
105
106
- # Specifies the attributes that will be included in the output of the #inspect method
106
+ ##
107
+ # :singleton-method:
108
+ #
109
+ # Specifies the attributes that will be included in the output of the
110
+ # #inspect method:
111
+ #
112
+ # Post.attributes_for_inspect = [:id, :title]
113
+ # Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
114
+ #
115
+ # When set to `:all` inspect will list all the record's attributes:
116
+ #
117
+ # Post.attributes_for_inspect = :all
118
+ # Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
107
119
class_attribute :attributes_for_inspect , instance_accessor : false , default : :all
108
120
109
121
def self . application_record_class? # :nodoc:
@@ -728,12 +740,26 @@ def connection_handler
728
740
self . class . connection_handler
729
741
end
730
742
731
- # Returns the attributes specified by <tt>.attributes_for_inspect</tt> as a nicely formatted string.
743
+ # Returns the attributes of the record as a nicely formatted string.
744
+ #
745
+ # Post.first.inspect
746
+ # #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
747
+ #
748
+ # The attributes can be limited by setting <tt>.attributes_for_inspect</tt>.
749
+ #
750
+ # Post.attributes_for_inspect = [:id, :title]
751
+ # Post.first.inspect
752
+ # #=> "#<Post id: 1, title: "Hello, World!">"
732
753
def inspect
733
754
inspect_with_attributes ( attributes_for_inspect )
734
755
end
735
756
736
- # Returns the full contents of the record as a nicely formatted string.
757
+ # Returns all attributes of the record as a nicely formatted string,
758
+ # ignoring <tt>.attributes_for_inspect</tt>.
759
+ #
760
+ # Post.first.full_inspect
761
+ # #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
762
+ #
737
763
def full_inspect
738
764
inspect_with_attributes ( all_attributes_for_inspect )
739
765
end
0 commit comments