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.
-
#block ⇒ Proc
readonly
Block at the call.
-
#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, block, 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, block, result) ⇒ Call
Initialize the call.
12 13 14 15 16 17 18 19 20 21 |
# 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 |
Instance Attribute Details
#arguments ⇒ Array (readonly)
Returns arguments at the call.
45 46 47 |
# File 'lib/peeek/call.rb', line 45 def arguments @arguments end |
#backtrace ⇒ Array<String> (readonly)
Returns backtrace the call occurred.
29 30 31 |
# File 'lib/peeek/call.rb', line 29 def backtrace @backtrace end |
#block ⇒ Proc (readonly)
Returns block at the call.
49 50 51 |
# File 'lib/peeek/call.rb', line 49 def block @block end |
#exception ⇒ StandardError (readonly)
Returns exception that raised from the call.
64 65 66 67 |
# File 'lib/peeek/call.rb', line 64 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.
33 34 35 |
# File 'lib/peeek/call.rb', line 33 def file @file end |
#hook ⇒ Peeek::Hook (readonly)
Returns hook the call occurred.
25 26 27 |
# File 'lib/peeek/call.rb', line 25 def hook @hook end |
#line ⇒ Integer (readonly)
Returns line number the call occurred.
37 38 39 |
# File 'lib/peeek/call.rb', line 37 def line @line end |
#receiver ⇒ Module, ... (readonly)
Returns object that received the call.
41 42 43 |
# File 'lib/peeek/call.rb', line 41 def receiver @receiver end |
#result ⇒ Peeek::Call::Result (readonly)
Returns result of the call.
53 54 55 |
# File 'lib/peeek/call.rb', line 53 def result @result end |
#return_value ⇒ Object (readonly)
Returns value that the call returned.
57 58 59 60 |
# File 'lib/peeek/call.rb', line 57 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.
79 80 81 |
# File 'lib/peeek/call.rb', line 79 def raised? @result.is_a?(Exception) end |
#returned? ⇒ Boolean
Determine if the result is a return value.
72 73 74 |
# File 'lib/peeek/call.rb', line 72 def returned? @result.is_a?(ReturnValue) end |
#to_s ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# 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 |