Class: ObjectInspector::Inspector
- Inherits:
-
Object
- Object
- ObjectInspector::Inspector
- Defined in:
- lib/object_inspector/inspector.rb
Overview
ObjectInspector::Inspector organizes inspection of the associated #object via the passed in options and via a BaseFormatter instance.
Instance Attribute Summary collapse
-
#formatter ⇒ ObjectInspector::BaseFormatter
writeonly
(ObjectInspector.configuration.formatter) the formatter object type to use for formatting the inspect String.
-
#formatter_klass ⇒ Object
readonly
Returns the value of attribute formatter_klass.
-
#kargs ⇒ Hash
options to be sent to #object via the ObjectInterrogator when calling the ‘inspect_*` methods.
-
#object ⇒ Object
the object being inspected.
-
#scope ⇒ Symbol
Object inspection type.
Class Method Summary collapse
-
.inspect(object, **kargs) ⇒ String
Shortcuts the instantiation -> #to_s flow that would normally be required to use ObjectInspector::Inspector.
Instance Method Summary collapse
-
#flags ⇒ String, NilClass
Boolean flags/states applicable to #object.
-
#identification ⇒ String
Core object identification details, such as the #object class name and any core-level attributes.
-
#info ⇒ String, NilClass
Informational details applicable to #object.
-
#initialize(object, scope: ObjectInspector.configuration.default_scope, formatter: ObjectInspector.configuration.formatter_class, **kargs) ⇒ Inspector
constructor
A new instance of Inspector.
-
#issues ⇒ String, NilClass
Issues/Warnings applicable to #object.
-
#name ⇒ String, NilClass
The generally human-friendly unique identifier for #object.
-
#to_s ⇒ String
Generate the formatted inspect String.
-
#wrapped_object_inspection_result ⇒ String, NilClass
Generate the inspect String for the wrapped object, if present.
Constructor Details
#initialize(object, scope: ObjectInspector.configuration.default_scope, formatter: ObjectInspector.configuration.formatter_class, **kargs) ⇒ Inspector
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/object_inspector/inspector.rb', line 31 def initialize( object, scope: ObjectInspector.configuration.default_scope, formatter: ObjectInspector.configuration.formatter_class, **kargs) @object = object @scope = Conversions.Scope(scope) @formatter_klass = formatter @kargs = kargs end |
Instance Attribute Details
#formatter=(value) ⇒ ObjectInspector::BaseFormatter
(ObjectInspector.configuration.formatter) the formatter object type to use for formatting the inspect String
17 18 19 |
# File 'lib/object_inspector/inspector.rb', line 17 def formatter=(value) @formatter = value end |
#formatter_klass ⇒ Object (readonly)
Returns the value of attribute formatter_klass.
18 19 20 |
# File 'lib/object_inspector/inspector.rb', line 18 def formatter_klass @formatter_klass end |
#kargs ⇒ Hash
options to be sent to #object via the ObjectInterrogator when calling the ‘inspect_*` methods
17 18 19 |
# File 'lib/object_inspector/inspector.rb', line 17 def kargs @kargs end |
#object ⇒ Object
the object being inspected
17 18 19 |
# File 'lib/object_inspector/inspector.rb', line 17 def object @object end |
#scope ⇒ Symbol
Object inspection type. For example: :self (default) – Means: Only interrogate self. Don’t visit neighbors. <custom> – Anything else that makes sense for #object to key on
17 18 19 |
# File 'lib/object_inspector/inspector.rb', line 17 def scope @scope end |
Class Method Details
.inspect(object, **kargs) ⇒ String
Shortcuts the instantiation -> #to_s flow that would normally be required to use ObjectInspector::Inspector.
27 28 29 |
# File 'lib/object_inspector/inspector.rb', line 27 def self.inspect(object, **kargs) new(object, **kargs).to_s end |
Instance Method Details
#flags ⇒ String, NilClass
Boolean flags/states applicable to #object.
74 75 76 |
# File 'lib/object_inspector/inspector.rb', line 74 def flags value(key: :flags) end |
#identification ⇒ String
Core object identification details, such as the #object class name and any core-level attributes.
66 67 68 |
# File 'lib/object_inspector/inspector.rb', line 66 def identification (value(key: :identification) || object.class).to_s end |
#info ⇒ String, NilClass
Informational details applicable to #object.
90 91 92 |
# File 'lib/object_inspector/inspector.rb', line 90 def info value(key: :info) end |
#issues ⇒ String, NilClass
Issues/Warnings applicable to #object.
82 83 84 |
# File 'lib/object_inspector/inspector.rb', line 82 def issues value(key: :issues) end |
#name ⇒ String, NilClass
The generally human-friendly unique identifier for #object.
98 99 100 101 102 |
# File 'lib/object_inspector/inspector.rb', line 98 def name value(key: :name) || interrogate_object(method_name: :display_name, kargs: object_method_keyword_arguments) end |
#to_s ⇒ String
Generate the formatted inspect String.
45 46 47 |
# File 'lib/object_inspector/inspector.rb', line 45 def to_s formatter.call end |
#wrapped_object_inspection_result ⇒ String, NilClass
Generate the inspect String for the wrapped object, if present.
53 54 55 56 57 58 59 60 |
# File 'lib/object_inspector/inspector.rb', line 53 def wrapped_object_inspection_result return unless object_is_a_wrapper? self.class.inspect( extract_wrapped_object, scope: scope, formatter: formatter_klass) end |