Class: ObjectInspector::Configuration

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

Overview

ObjectInspector::Configuration stores the default configuration options for the ObjectInspector gem. Modification of attributes is possible at any time, and values will persist for the duration of the running process.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enabled: true, formatter_class: TemplatingFormatter, inspect_method_prefix: "inspect", default_scope: Scope.new(:self), wild_card_scope: "all", out_of_scope_placeholder: "*", presented_object_separator: " #{[0x21E8].pack("U")} ", name_separator: " - ", flags_separator: " / ", issues_separator: " | ", info_separator: " | ", error_handler: ->(exception, object:) {}) ⇒ Configuration

:reek:LongParameterList, :reek:BooleanParameter



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/object_inspector.rb', line 80

def initialize( # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
  enabled: true,
  formatter_class: TemplatingFormatter,
  inspect_method_prefix: "inspect",
  default_scope: Scope.new(:self),
  wild_card_scope: "all",
  out_of_scope_placeholder: "*",
  presented_object_separator: " #{[0x21E8].pack("U")} ", # This is: " ⇨ "
  name_separator: " - ",
  flags_separator: " / ",
  issues_separator: " | ",
  info_separator: " | ",
  error_handler: ->(exception, object:) {}
)
  @enabled = enabled
  @formatter_class = formatter_class
  @inspect_method_prefix = inspect_method_prefix
  @default_scope = default_scope
  @wild_card_scope = wild_card_scope
  @out_of_scope_placeholder = out_of_scope_placeholder
  @presented_object_separator = presented_object_separator
  @name_separator = name_separator
  @flags_separator = flags_separator
  @issues_separator = issues_separator
  @info_separator = info_separator
  self.error_handler = error_handler
end

Instance Attribute Details

#default_scopeObject

Returns the value of attribute default_scope.



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

def default_scope
  @default_scope
end

#error_handlerObject

Returns the value of attribute error_handler.



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

def error_handler
  @error_handler
end

#flags_separatorObject

Returns the value of attribute flags_separator.



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

def flags_separator
  @flags_separator
end

#formatter_classObject

Returns the value of attribute formatter_class.



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

def formatter_class
  @formatter_class
end

#info_separatorObject

Returns the value of attribute info_separator.



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

def info_separator
  @info_separator
end

#inspect_method_prefixObject

Returns the value of attribute inspect_method_prefix.



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

def inspect_method_prefix
  @inspect_method_prefix
end

#issues_separatorObject

Returns the value of attribute issues_separator.



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

def issues_separator
  @issues_separator
end

#name_separatorObject

Returns the value of attribute name_separator.



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

def name_separator
  @name_separator
end

#out_of_scope_placeholderObject

Returns the value of attribute out_of_scope_placeholder.



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

def out_of_scope_placeholder
  @out_of_scope_placeholder
end

#presented_object_separatorObject

Returns the value of attribute presented_object_separator.



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

def presented_object_separator
  @presented_object_separator
end

#wild_card_scopeObject

Returns the value of attribute wild_card_scope.



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

def wild_card_scope
  @wild_card_scope
end

Instance Method Details

#disableObject

Disable Object Inspector for the current process and print a status message to $stdout.



131
132
133
134
# File 'lib/object_inspector.rb', line 131

def disable
  self.enabled = false
  puts(" -> ObjectInspector disabled")
end

#disabled?Boolean

Returns:

  • (Boolean)


127
# File 'lib/object_inspector.rb', line 127

def disabled? = !enabled?

#enableObject

Enable Object Inspector for the current process and print a status message to $stdout.



121
122
123
124
# File 'lib/object_inspector.rb', line 121

def enable
  self.enabled = true
  puts(" -> ObjectInspector enabled")
end

#enabled=(value) ⇒ Object

Parameters:

  • value (Object)

    Coerced to a Boolean with !!value.



109
110
111
# File 'lib/object_inspector.rb', line 109

def enabled=(value)
  @enabled = !!value
end

#enabled?Boolean

Returns:

  • (Boolean)


117
# File 'lib/object_inspector.rb', line 117

def enabled? = @enabled

#toggleObject

Toggles between #enable and #disable based on #enabled?.



114
# File 'lib/object_inspector.rb', line 114

def toggle = enabled? ? disable : enable