Class: Peeek::Call
- Inherits:
-
Object
- Object
- Peeek::Call
- Defined in:
- lib/peeek/call.rb
Defined Under Namespace
Classes: Exception, Result, ReturnValue
Instance Attribute Summary collapse
-
#arguments ⇒ Array
readonly
Arguments at the call.
-
#backtrace ⇒ Array<String>
readonly
Backtrace the call occurred.
-
#exception ⇒ StandardError
readonly
Exception that raised from the call.
-
#file ⇒ String
readonly
Name of file the call occurred.
-
#hook ⇒ Peeek::Hook
readonly
Hook the call occurred.
-
#line ⇒ Integer
readonly
Line number the call occurred.
-
#receiver ⇒ Module, ...
readonly
Object that received the call.
-
#result ⇒ Peeek::Call::Result
readonly
Result of the call.
-
#return_value ⇒ Object
readonly
Value that the call returned.
Instance Method Summary collapse
-
#initialize(hook, backtrace, receiver, arguments, result) ⇒ Call
constructor
Initialize the call.
-
#raised? ⇒ Boolean
Determine if the result is an exception.
-
#returned? ⇒ Boolean
Determine if the result is a return value.
- #to_s ⇒ Object
Constructor Details
#initialize(hook, backtrace, receiver, arguments, result) ⇒ Call
Initialize the call.
11 12 13 14 15 16 17 18 19 |
# File 'lib/peeek/call.rb', line 11 def initialize(hook, backtrace, receiver, arguments, 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 @result = result end |
Instance Attribute Details
#arguments ⇒ Array (readonly)
Returns arguments at the call.
43 44 45 |
# File 'lib/peeek/call.rb', line 43 def arguments @arguments end |
#backtrace ⇒ Array<String> (readonly)
Returns backtrace the call occurred.
27 28 29 |
# File 'lib/peeek/call.rb', line 27 def backtrace @backtrace end |
#exception ⇒ StandardError (readonly)
Returns exception that raised from the call.
58 59 60 61 |
# File 'lib/peeek/call.rb', line 58 def exception raise TypeError, "the call didn't raised an exception" unless raised? @result.value end |
#file ⇒ String (readonly)
Returns name of file the call occurred.
31 32 33 |
# File 'lib/peeek/call.rb', line 31 def file @file end |
#hook ⇒ Peeek::Hook (readonly)
Returns hook the call occurred.
23 24 25 |
# File 'lib/peeek/call.rb', line 23 def hook @hook end |
#line ⇒ Integer (readonly)
Returns line number the call occurred.
35 36 37 |
# File 'lib/peeek/call.rb', line 35 def line @line end |
#receiver ⇒ Module, ... (readonly)
Returns object that received the call.
39 40 41 |
# File 'lib/peeek/call.rb', line 39 def receiver @receiver end |
#result ⇒ Peeek::Call::Result (readonly)
Returns result of the call.
47 48 49 |
# File 'lib/peeek/call.rb', line 47 def result @result end |
#return_value ⇒ Object (readonly)
Returns value that the call returned.
51 52 53 54 |
# File 'lib/peeek/call.rb', line 51 def return_value raise TypeError, "the call didn't return a value" unless returned? @result.value end |
Instance Method Details
#raised? ⇒ Boolean
Determine if the result is an exception.
73 74 75 |
# File 'lib/peeek/call.rb', line 73 def raised? @result.is_a?(Exception) end |
#returned? ⇒ Boolean
Determine if the result is a return value.
66 67 68 |
# File 'lib/peeek/call.rb', line 66 def returned? @result.is_a?(ReturnValue) end |
#to_s ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/peeek/call.rb', line 77 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 returned? parts << "returned #{return_value.inspect}" elsif raised? parts << "raised #{exception.inspect}" end parts << "in #{@file}" parts << "at #{@line}" parts * ' ' end |