Class: Contracts::Context
- Inherits:
-
Object
- Object
- Contracts::Context
- Defined in:
- lib/contracts.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#before ⇒ Object
Returns the value of attribute before.
-
#block_given ⇒ Object
readonly
Returns the value of attribute block_given.
-
#contract ⇒ Object
readonly
Returns the value of attribute contract.
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#finished_at ⇒ Object
Returns the value of attribute finished_at.
-
#keyword_arguments ⇒ Object
readonly
Returns the value of attribute keyword_arguments.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
-
#result ⇒ Object
Returns the value of attribute result.
-
#source_location ⇒ Object
readonly
Returns the value of attribute source_location.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize(receiver:, contract:, arguments:, keyword_arguments:, block_given:, parent: nil) ⇒ Context
constructor
A new instance of Context.
Constructor Details
#initialize(receiver:, contract:, arguments:, keyword_arguments:, block_given:, parent: nil) ⇒ Context
Returns a new instance of Context.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/contracts.rb', line 113 def initialize(receiver:, contract:, arguments:, keyword_arguments:, block_given:, parent: nil) @receiver = receiver @contract = contract @owner = contract.owner @method_name = contract.method_name @arguments = arguments.freeze @keyword_arguments = keyword_arguments.freeze @block_given = block_given @started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) @source_location = contract.source_location @parent = parent @depth = parent ? parent.depth + 1 : 0 @trace_id = parent ? parent.trace_id : "c#{object_id.to_s(36)}" end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
110 111 112 |
# File 'lib/contracts.rb', line 110 def arguments @arguments end |
#before ⇒ Object
Returns the value of attribute before.
109 110 111 |
# File 'lib/contracts.rb', line 109 def before @before end |
#block_given ⇒ Object (readonly)
Returns the value of attribute block_given.
110 111 112 |
# File 'lib/contracts.rb', line 110 def block_given @block_given end |
#contract ⇒ Object (readonly)
Returns the value of attribute contract.
110 111 112 |
# File 'lib/contracts.rb', line 110 def contract @contract end |
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
110 111 112 |
# File 'lib/contracts.rb', line 110 def depth @depth end |
#exception ⇒ Object
Returns the value of attribute exception.
109 110 111 |
# File 'lib/contracts.rb', line 109 def exception @exception end |
#finished_at ⇒ Object
Returns the value of attribute finished_at.
109 110 111 |
# File 'lib/contracts.rb', line 109 def finished_at @finished_at end |
#keyword_arguments ⇒ Object (readonly)
Returns the value of attribute keyword_arguments.
110 111 112 |
# File 'lib/contracts.rb', line 110 def keyword_arguments @keyword_arguments end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
110 111 112 |
# File 'lib/contracts.rb', line 110 def method_name @method_name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
110 111 112 |
# File 'lib/contracts.rb', line 110 def owner @owner end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
110 111 112 |
# File 'lib/contracts.rb', line 110 def parent @parent end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
110 111 112 |
# File 'lib/contracts.rb', line 110 def receiver @receiver end |
#result ⇒ Object
Returns the value of attribute result.
109 110 111 |
# File 'lib/contracts.rb', line 109 def result @result end |
#source_location ⇒ Object (readonly)
Returns the value of attribute source_location.
110 111 112 |
# File 'lib/contracts.rb', line 110 def source_location @source_location end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
110 111 112 |
# File 'lib/contracts.rb', line 110 def started_at @started_at end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
110 111 112 |
# File 'lib/contracts.rb', line 110 def trace_id @trace_id end |
Instance Method Details
#duration ⇒ Object
128 |
# File 'lib/contracts.rb', line 128 def duration = @finished_at && (@finished_at - @started_at) |