class Peeek::Call
Attributes
@attribute [r] arguments @return [Array] arguments at the call
@attribute [r] backtrace @return [Array<String>] backtrace the call occurred
@attribute [r] block @return [Proc] block at the call
@attribute [r] file @return [String] name of file the call occurred
@attribute [r] hook @return [Peeek::Hook] hook the call occurred
@attribute [r] line @return [Integer] line number the call occurred
@attribute [r] receiver @return [Module, Class, Object] object that received the call
@attribute [r] result @return [Peeek::Call::Result] result of the call
Public Class Methods
Initialize the call.
@param [Peeek::Hook] hook hook the call occurred @param [Array<String>] backtrace backtrace the call occurred @param [Module, Class, Object] receiver object that received the call @param [Array] arguments arguments at the call @param [Proc] block block at the call @param [Peeek::Call::Result] result result of the call
# File lib/peeek/call.rb, line 12 def initialize(hook, backtrace, receiver, arguments, block, result) raise ArgumentError, 'invalid as result' unless result.is_a?(Result) @hook = hook @backtrace = backtrace @file, @line = extract_file_and_line(backtrace.first) @receiver = receiver @arguments = arguments @block = block @result = result end
Public Instance Methods
@attribute [r] exception @return [StandardError] exception that raised from the call
# File lib/peeek/call.rb, line 64 def exception raise TypeError, "the call didn't raised an exception" unless raised? @result.value end
Determine if the result is an exception.
@return whether the result is an exception
# File lib/peeek/call.rb, line 79 def raised? @result.is_a?(Exception) end
@attribute [r] return_value
@return [Object] value that the call returned
# File lib/peeek/call.rb, line 57 def return_value raise TypeError, "the call didn't return a value" unless returned? @result.value end
Determine if the result is a return value.
@return whether the result is a return value
# File lib/peeek/call.rb, line 72 def returned? @result.is_a?(ReturnValue) end
# File lib/peeek/call.rb, line 83 def to_s parts = [@hook.to_s] parts << "from #{@receiver.inspect}" if @arguments.size == 1 parts << "with #{@arguments.first.inspect}" elsif @arguments.size > 1 parts << "with (#{@arguments.map(&:inspect) * ', '})" end if @block conjunction = @arguments.empty? ? 'with' : 'and' parts << "#{conjunction} a block" end if returned? parts << "returned #{return_value.inspect}" elsif raised? parts << "raised #{exception.inspect}" end parts << "in #{@file}" parts << "at #{@line}" parts * ' ' end
Private Instance Methods
# File lib/peeek/call.rb, line 111 def extract_file_and_line(string) _, file, line = /^(.+):(\d+)(?::in\s+|$)/.match(string).to_a raise ArgumentError, 'invalid as string of backtrace' unless file and line [file, line.to_i] end