Class: ObjectTracer::Output::PayloadWrapper
- Inherits:
-
Object
- Object
- ObjectTracer::Output::PayloadWrapper
- Defined in:
- lib/object_tracer/output/payload_wrapper.rb
Constant Summary collapse
- UNDEFINED =
"[undefined]"
- PRIVATE_MARK =
" (private)"
- PASTEL =
Pastel.new
- PAYLOAD_ATTRIBUTES =
{ method_name: {symbol: "", color: :bright_blue}, location: {symbol: "from:", color: :green}, return_value: {symbol: "=>", color: :magenta}, arguments: {symbol: "<=", color: :orange}, ivar_changes: {symbol: "changes:\n", color: :blue}, defined_class: {symbol: "#", color: :yellow} }
Instance Method Summary collapse
- #arguments(options = {}) ⇒ Object
- #call_info_with_ivar_changes(options = {}) ⇒ Object
- #detail_call_info(options = {}) ⇒ Object
-
#initialize(payload) ⇒ PayloadWrapper
constructor
A new instance of PayloadWrapper.
- #ivar_changes(options = {}) ⇒ Object
- #location(options = {}) ⇒ Object
- #method_head ⇒ Object
- #method_name(options = {}) ⇒ Object
- #passed_at(options = {}) ⇒ Object
- #raw_arguments ⇒ Object
- #raw_return_value ⇒ Object
- #return_value(options = {}) ⇒ Object
Constructor Details
#initialize(payload) ⇒ PayloadWrapper
Returns a new instance of PayloadWrapper.
31 32 33 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 31 def initialize(payload) @payload = payload end |
Instance Method Details
#arguments(options = {}) ⇒ Object
44 45 46 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 44 def arguments( = {}) generate_string_result(raw_arguments, [:inspect]) end |
#call_info_with_ivar_changes(options = {}) ⇒ Object
132 133 134 135 136 137 138 139 140 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 132 def call_info_with_ivar_changes( = {}) <<~MSG #{method_name_and_defined_class()} from: #{location()} changes: #{ivar_changes()} MSG end |
#detail_call_info(options = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 107 def detail_call_info( = {}) <<~MSG #{method_name_and_defined_class()} from: #{location()} <= #{arguments()} => #{return_value()} MSG end |
#ivar_changes(options = {}) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 117 def ivar_changes( = {}) @payload.ivar_changes.map do |ivar, value_changes| before = generate_string_result(value_changes[:before], [:inspect]) after = generate_string_result(value_changes[:after], [:inspect]) if [:colorize] ivar = PASTEL.orange(ivar.to_s) before = PASTEL.bright_blue(before.to_s) after = PASTEL.bright_blue(after.to_s) end " #{ivar}: #{before} => #{after}" end.join("\n") end |
#location(options = {}) ⇒ Object
24 25 26 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 24 def location( = {}) @payload.location() end |
#method_head ⇒ Object
20 21 22 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 20 def method_head @payload.method_head end |
#method_name(options = {}) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 35 def method_name( = {}) name = ":#{@payload.method_name}" name += " [#{tag}]" if tag name += PRIVATE_MARK if is_private_call? name end |
#passed_at(options = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 94 def passed_at( = {}) with_method_head = .fetch(:with_method_head, false) arg_name = raw_arguments.keys.detect { |k| raw_arguments[k] == target } return unless arg_name arg_name = ":#{arg_name}" arg_name = PASTEL.orange(arg_name) if [:colorize] msg = "Passed as #{arg_name} in '#{defined_class()}##{method_name()}' at #{location()}\n" msg += " > #{method_head}\n" if with_method_head msg end |
#raw_arguments ⇒ Object
28 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 28 alias :raw_arguments :arguments |
#raw_return_value ⇒ Object
29 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 29 alias :raw_return_value :return_value |
#return_value(options = {}) ⇒ Object
48 49 50 |
# File 'lib/object_tracer/output/payload_wrapper.rb', line 48 def return_value( = {}) generate_string_result(raw_return_value, [:inspect]) end |