Module: ActiveRecordCompose::Inspectable
- Extended by:
- ActiveSupport::Concern
- Includes:
- Attributes
- Included in:
- Model
- Defined in:
- lib/active_record_compose/inspectable.rb
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<Symbol>
Returns columns not to expose when invoking #inspect.
-
.filter_attributes=(value) ⇒ void
Specify columns not to expose when invoking #inspect.
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
attribute_names, #attribute_names, #attributes, delegate_attribute
Class Method Details
.filter_attributes ⇒ Array<Symbol>
Returns columns not to expose when invoking #inspect.
64 65 66 67 68 69 70 |
# File 'lib/active_record_compose/inspectable.rb', line 64 def filter_attributes if @filter_attributes.nil? superclass.filter_attributes else @filter_attributes end end |
.filter_attributes=(value) ⇒ void
Specify columns not to expose when invoking #inspect.
76 77 78 79 |
# File 'lib/active_record_compose/inspectable.rb', line 76 def filter_attributes=(value) @inspection_filter = nil @filter_attributes = value end |
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
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 |