Class: ObjectInspector::Inspector

Inherits:
Object
  • Object
show all
Defined in:
lib/object_inspector/inspector.rb

Overview

ObjectInspector::Inspector organizes inspection of the associated #object via the passed in options and via an BaseFormatter instance.

:reek:TooManyMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, scope: ObjectInspector.configuration.default_scope, formatter: ObjectInspector.configuration.formatter_class, **kwargs) ⇒ Inspector

:reek:DuplicateMethodCall (ObjectInspecto.configuration)

Parameters:

  • object (Object)

    the object being inspected

  • scope (Symbol) (defaults to: ObjectInspector.configuration.default_scope)

    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
    
  • formatter (ObjectInspector::BaseFormatter) (defaults to: ObjectInspector.configuration.formatter_class)

    (ObjectInspector.configuration.formatter) the formatter object type to use for formatting the inspect String

  • kwargs (Hash)

    options to be sent to #object via the ObjectInterrogator when calling the ‘inspect_*` methods



32
33
34
35
36
37
38
39
40
41
# File 'lib/object_inspector/inspector.rb', line 32

def initialize(
      object,
      scope: ObjectInspector.configuration.default_scope,
      formatter: ObjectInspector.configuration.formatter_class,
      **kwargs)
  @object = object
  @scope = ObjectInspector::Conversions.Scope(scope)
  @formatter_klass = formatter
  @kwargs = kwargs
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



9
10
11
# File 'lib/object_inspector/inspector.rb', line 9

def object
  @object
end

Class Method Details

.inspectString

Shortcuts the instantiation -> #to_s flow that would normally be required to use ObjectInspector::Inspector.

Returns:

  • (String)


15
16
17
# File 'lib/object_inspector/inspector.rb', line 15

def self.inspect(...)
  new(...).to_s
end

Instance Method Details

#flagsString, NilClass

Boolean flags/states applicable to #object.

Returns:

  • (String)

    if given

  • (NilClass)

    if not given



76
77
78
# File 'lib/object_inspector/inspector.rb', line 76

def flags
  value(key: :flags)
end

#identificationString

Core object identification details, such as the #object class name and any core-level attributes.

Returns:

  • (String)


68
69
70
# File 'lib/object_inspector/inspector.rb', line 68

def identification
  (value(key: :identification) || @object.class).to_s
end

#infoString, NilClass

Informational details applicable to #object.

Returns:

  • (String)

    if given

  • (NilClass)

    if not given



92
93
94
# File 'lib/object_inspector/inspector.rb', line 92

def info
  value(key: :info)
end

#issuesString, NilClass

Issues/Warnings applicable to #object.

Returns:

  • (String)

    if given

  • (NilClass)

    if not given



84
85
86
# File 'lib/object_inspector/inspector.rb', line 84

def issues
  value(key: :issues)
end

#nameString, NilClass

A human-friendly identifier for #object.

Returns:

  • (String)

    if given

  • (NilClass)

    if not given



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/object_inspector/inspector.rb', line 100

def name
  key = :name

  if @kwargs.key?(key)
    value(key: key)
  else
    interrogate_object_inspect_method(key) ||
      interrogate_object(
        method_name: :display_name, kwargs: object_method_keyword_arguments)
  end
end

#to_sString

Generate the formatted inspect String.

Returns:

  • (String)


46
47
48
# File 'lib/object_inspector/inspector.rb', line 46

def to_s
  formatter.call
end

#wrapped_object_inspection_resultString, NilClass

Generate the inspect String for the wrapped object, if present.

Returns:

  • (String)

    if #object_is_a_wrapper?

  • (NilClass)

    if not #object_is_a_wrapper?



54
55
56
57
58
59
60
61
62
# File 'lib/object_inspector/inspector.rb', line 54

def wrapped_object_inspection_result
  return unless object_is_a_wrapper?

  self.class.inspect(
    extract_wrapped_object,
    scope: @scope,
    formatter: @formatter_klass,
    kwargs: @kwargs)
end