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 a BaseFormatter instance.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Inspector.



29
30
31
32
33
34
35
36
37
38
# File 'lib/object_inspector/inspector.rb', line 29

def initialize(
      object,
      scope: :self,
      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

Parameters:

Returns:



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

def formatter=(value)
  @formatter = value
end

#formatter_klassObject (readonly)

Returns the value of attribute formatter_klass.



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

def formatter_klass
  @formatter_klass
end

#kargsHash

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

Returns:

  • (Hash)

    the current value of kargs



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

def kargs
  @kargs
end

#objectObject

the object being inspected

Returns:

  • (Object)

    the current value of object



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

def object
  @object
end

#scopeSymbol

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

Returns:

  • (Symbol)

    the current value of scope



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

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.

Returns:

  • (String)


25
26
27
# File 'lib/object_inspector/inspector.rb', line 25

def self.inspect(object, **kargs)
  new(object, **kargs).to_s
end

Instance Method Details

#flagsString, NilClass

Boolean flags/states applicable to #object.

Returns:

  • (String)

    if given

  • (NilClass)

    if not given



72
73
74
# File 'lib/object_inspector/inspector.rb', line 72

def flags
  value(key: :flags)
end

#identificationString

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

Returns:

  • (String)


64
65
66
# File 'lib/object_inspector/inspector.rb', line 64

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



80
81
82
# File 'lib/object_inspector/inspector.rb', line 80

def info
  value(key: :info)
end

#nameString, NilClass

The generally human-friendly unique identifier for #object.

Returns:

  • (String)

    if given

  • (NilClass)

    if not given



88
89
90
91
92
# File 'lib/object_inspector/inspector.rb', line 88

def name
  value(key: :name) ||
    interrogate_object(method_name: :display_name,
                       kargs: object_method_keyword_arguments)
end

#to_sString

Generate the formatted inspect String.

Returns:

  • (String)


43
44
45
# File 'lib/object_inspector/inspector.rb', line 43

def to_s
  formatter.call
end

#wrapped_object_inspectionString, 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



51
52
53
54
55
56
57
58
# File 'lib/object_inspector/inspector.rb', line 51

def wrapped_object_inspection
  if object_is_a_wrapper?
    self.class.inspect(
      extract_wrapped_object,
      scope: scope,
      formatter: formatter_klass)
  end
end