Module: ActiveRecordCompose::Inspectable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Attributes
- Included in:
- Model
- Defined in:
- lib/active_record_compose/inspectable.rb,
sig/_internal/package_private.rbs
Overview
It provides #inspect behavior. It tries to replicate the inspect format provided by ActiveRecord as closely as possible.
Class Method Summary collapse
- .filter_attributes ⇒ Array[untyped]
- .filter_attributes= ⇒ void
- .inspection_filter ⇒ ActiveSupport::ParameterFilter
Instance Method Summary collapse
-
#inspect ⇒ String
Returns a formatted string representation of the record's attributes.
-
#pretty_print(pp) ⇒ void
It takes a PP and pretty prints that record.
Methods included from Attributes
#_require_attributes_initialized, #_write_attribute, #attribute, #attribute_names, #attributes, delegate_attribute, delegated_attributes, #delegated_attributes, delegated_attributes=
Class Method Details
.filter_attributes ⇒ Array[untyped]
94 |
# File 'sig/_internal/package_private.rbs', line 94
def self.filter_attributes: () -> Array[untyped]
|
.filter_attributes= ⇒ void
This method returns an undefined value.
95 |
# File 'sig/_internal/package_private.rbs', line 95
def self.filter_attributes=: (Array[untyped]) -> void
|
.inspection_filter ⇒ ActiveSupport::ParameterFilter
93 |
# File 'sig/_internal/package_private.rbs', line 93
def self.inspection_filter: () -> ActiveSupport::ParameterFilter
|
Instance Method Details
#inspect ⇒ String
Returns a formatted string representation of the record's attributes. It tries to replicate the inspect format provided by ActiveRecord as closely as possible.
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/active_record_compose/inspectable.rb', line 135 def inspect inspection = if @attributes attributes.map { |k, v| "#{k}: #{format_for_inspect(k, v)}" }.join(", ") else "not initialized" end "#<#{self.class} #{inspection}>" end |
#pretty_print(pp) ⇒ void
This method returns an undefined value.
It takes a PP and pretty prints that record.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/active_record_compose/inspectable.rb', line 148 def pretty_print(pp) pp.object_address_group(self) do if @attributes attrs = attributes pp.seplist(attrs.keys, proc { pp.text "," }) do |attr| pp.breakable " " pp.group(1) do pp.text attr pp.text ":" pp.breakable pp.text format_for_inspect(attr, attrs[attr]) end end else pp.breakable " " pp.text "not initialized" end end end |