Exception: Contracts::Violation

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

Direct Known Subclasses

CompositeViolation

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Error

#to_h

Constructor Details

#initialize(message = nil, owner: nil, method_name: nil, contract_type: nil, description: nil, expected: nil, actual: nil, parameter: nil, context: nil, source_location: nil, original_exception: nil) ⇒ Violation

Returns a new instance of Violation.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/contracts.rb', line 23

def initialize(message = nil, owner: nil, method_name: nil, contract_type: nil, description: nil, expected: nil,
               actual: nil, parameter: nil, context: nil, source_location: nil, original_exception: nil)
  @owner = owner
  @method_name = method_name
  @contract_type = contract_type
  @description = description
  @expected = expected
  @actual = actual
  @parameter = parameter
  @context = context
  @source_location = source_location
  @original_exception = original_exception
  super(message || "#{owner}##{method_name} violated #{contract_type}: #{description || expected}")
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



20
21
22
# File 'lib/contracts.rb', line 20

def actual
  @actual
end

#contextObject (readonly)

Returns the value of attribute context.



20
21
22
# File 'lib/contracts.rb', line 20

def context
  @context
end

#contract_typeObject (readonly)

Returns the value of attribute contract_type.



20
21
22
# File 'lib/contracts.rb', line 20

def contract_type
  @contract_type
end

#descriptionObject (readonly)

Returns the value of attribute description.



20
21
22
# File 'lib/contracts.rb', line 20

def description
  @description
end

#expectedObject (readonly)

Returns the value of attribute expected.



20
21
22
# File 'lib/contracts.rb', line 20

def expected
  @expected
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



20
21
22
# File 'lib/contracts.rb', line 20

def method_name
  @method_name
end

#original_exceptionObject (readonly)

Returns the value of attribute original_exception.



20
21
22
# File 'lib/contracts.rb', line 20

def original_exception
  @original_exception
end

#ownerObject (readonly)

Returns the value of attribute owner.



20
21
22
# File 'lib/contracts.rb', line 20

def owner
  @owner
end

#parameterObject (readonly)

Returns the value of attribute parameter.



20
21
22
# File 'lib/contracts.rb', line 20

def parameter
  @parameter
end

#source_locationObject (readonly)

Returns the value of attribute source_location.



20
21
22
# File 'lib/contracts.rb', line 20

def source_location
  @source_location
end