Class: TappingDevice::Output::PayloadWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/tapping_device/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

Constructor Details

#initialize(payload) ⇒ PayloadWrapper

Returns a new instance of PayloadWrapper.



31
32
33
# File 'lib/tapping_device/output/payload_wrapper.rb', line 31

def initialize(payload)
  @payload = payload
end

Instance Method Details

#arguments(options = {}) ⇒ Object



44
45
46
# File 'lib/tapping_device/output/payload_wrapper.rb', line 44

def arguments(options = {})
  generate_string_result(raw_arguments, options[:inspect])
end

#call_info_with_ivar_changes(options = {}) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/tapping_device/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 = {}) ⇒ Object



107
108
109
110
111
112
113
114
115
# File 'lib/tapping_device/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 = {}) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/tapping_device/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 = {}) ⇒ Object



24
25
26
# File 'lib/tapping_device/output/payload_wrapper.rb', line 24

def location(options = {})
  @payload.location(options)
end

#method_headObject



20
21
22
# File 'lib/tapping_device/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/tapping_device/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 = {}) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/tapping_device/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_argumentsObject



28
# File 'lib/tapping_device/output/payload_wrapper.rb', line 28

alias :raw_arguments :arguments

#raw_return_valueObject



29
# File 'lib/tapping_device/output/payload_wrapper.rb', line 29

alias :raw_return_value :return_value

#return_value(options = {}) ⇒ Object



48
49
50
# File 'lib/tapping_device/output/payload_wrapper.rb', line 48

def return_value(options = {})
  generate_string_result(raw_return_value, options[:inspect])
end