Class: Contracts::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/contracts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argumentsObject (readonly)

Returns the value of attribute arguments.



110
111
112
# File 'lib/contracts.rb', line 110

def arguments
  @arguments
end

#beforeObject

Returns the value of attribute before.



109
110
111
# File 'lib/contracts.rb', line 109

def before
  @before
end

#block_givenObject (readonly)

Returns the value of attribute block_given.



110
111
112
# File 'lib/contracts.rb', line 110

def block_given
  @block_given
end

#contractObject (readonly)

Returns the value of attribute contract.



110
111
112
# File 'lib/contracts.rb', line 110

def contract
  @contract
end

#depthObject (readonly)

Returns the value of attribute depth.



110
111
112
# File 'lib/contracts.rb', line 110

def depth
  @depth
end

#exceptionObject

Returns the value of attribute exception.



109
110
111
# File 'lib/contracts.rb', line 109

def exception
  @exception
end

#finished_atObject

Returns the value of attribute finished_at.



109
110
111
# File 'lib/contracts.rb', line 109

def finished_at
  @finished_at
end

#keyword_argumentsObject (readonly)

Returns the value of attribute keyword_arguments.



110
111
112
# File 'lib/contracts.rb', line 110

def keyword_arguments
  @keyword_arguments
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



110
111
112
# File 'lib/contracts.rb', line 110

def method_name
  @method_name
end

#ownerObject (readonly)

Returns the value of attribute owner.



110
111
112
# File 'lib/contracts.rb', line 110

def owner
  @owner
end

#parentObject (readonly)

Returns the value of attribute parent.



110
111
112
# File 'lib/contracts.rb', line 110

def parent
  @parent
end

#receiverObject (readonly)

Returns the value of attribute receiver.



110
111
112
# File 'lib/contracts.rb', line 110

def receiver
  @receiver
end

#resultObject

Returns the value of attribute result.



109
110
111
# File 'lib/contracts.rb', line 109

def result
  @result
end

#source_locationObject (readonly)

Returns the value of attribute source_location.



110
111
112
# File 'lib/contracts.rb', line 110

def source_location
  @source_location
end

#started_atObject (readonly)

Returns the value of attribute started_at.



110
111
112
# File 'lib/contracts.rb', line 110

def started_at
  @started_at
end

#trace_idObject (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

#durationObject



128
# File 'lib/contracts.rb', line 128

def duration = @finished_at && (@finished_at - @started_at)