class ObjectTracer::Output::PayloadWrapper

Constants

PASTEL
PAYLOAD_ATTRIBUTES
PRIVATE_MARK
UNDEFINED

Public Class Methods

new(payload) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 31
def initialize(payload)
  @payload = payload
end

Public Instance Methods

arguments(options = {}) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 44
def arguments(options = {})
  generate_string_result(raw_arguments, options[:inspect])
end
Also aliased as: raw_arguments
call_info_with_ivar_changes(options = {}) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 132
      def call_info_with_ivar_changes(options = {})
        <<~MSG
        #{method_name_and_defined_class(options)}
            from: #{location(options)}
            changes:
        #{ivar_changes(options)}

        MSG
      end
detail_call_info(options = {}) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 107
      def detail_call_info(options = {})
        <<~MSG
        #{method_name_and_defined_class(options)}
            from: #{location(options)}
            <= #{arguments(options)}
            => #{return_value(options)}

        MSG
      end
ivar_changes(options = {}) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 117
def ivar_changes(options = {})
  @payload.ivar_changes.map do |ivar, value_changes|
    before = generate_string_result(value_changes[:before], options[:inspect])
    after = generate_string_result(value_changes[:after], options[:inspect])

    if options[: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 = {}) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 24
def location(options = {})
  @payload.location(options)
end
method_head() click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 20
def method_head
  @payload.method_head
end
method_name(options = {}) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 35
def method_name(options = {})
  name = ":#{@payload.method_name}"

  name += " [#{tag}]" if tag
  name += PRIVATE_MARK if is_private_call?

  name
end
passed_at(options = {}) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 94
def passed_at(options = {})
  with_method_head = options.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 options[:colorize]
  msg = "Passed as #{arg_name} in '#{defined_class(options)}##{method_name(options)}' at #{location(options)}\n"
  msg += "  > #{method_head}\n" if with_method_head
  msg
end
raw_arguments(options = {})
Alias for: arguments
raw_return_value(options = {})
Alias for: return_value
return_value(options = {}) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 48
def return_value(options = {})
  generate_string_result(raw_return_value, options[:inspect])
end
Also aliased as: raw_return_value

Private Instance Methods

array_to_string(array, inspect) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 161
def array_to_string(array, inspect)
  elements_string = array.map do |elem|
    generate_string_result(elem, inspect)
  end.join(", ")
  "[#{elements_string}]"
end
generate_string_result(obj, inspect) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 144
def generate_string_result(obj, inspect)
  case obj
  when Array
    array_to_string(obj, inspect)
  when Hash
    hash_to_string(obj, inspect)
  when UNDEFINED
    UNDEFINED
  when String
    "\"#{obj}\""
  when nil
    "nil"
  else
    inspect ? obj.inspect : obj.to_s
  end
end
hash_to_string(hash, inspect) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 168
def hash_to_string(hash, inspect)
  elements_string = hash.map do |key, value|
    "#{key.to_s}: #{generate_string_result(value, inspect)}"
  end.join(", ")
  "{#{elements_string}}"
end
obj_to_string(element, inspect) click to toggle source
# File lib/object_tracer/output/payload_wrapper.rb, line 175
def obj_to_string(element, inspect)
  to_string_method = inspect ? :inspect : :to_s

  if !inspect && element.is_a?(String)
    "\"#{element}\""
  else
    element.send(to_string_method)
  end
end