Class: Assertion::Inversion Private

Inherits:
Base
  • Object
show all
Defined in:
lib/assertion/inversion.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Describes the inversion of the assertion object

The inversion decorates the source assertion switching its message (from falsey to truthy) and reverting its ‘check`.

Examples:

IsAdult = Assertion.about :name, :age do
  age >= 18
end

assertion = IsAdult.new
inversion = Inversion.new(assertion)

assertion.call.valid? == inversion.call.invalid? # => true

Class Attribute Summary collapse

Attributes inherited from Base

#attributes

Class Method Summary collapse

Methods inherited from Base

call, translate, translator

Methods included from DSL::Attributes

#attribute, #attributes, extended

Methods included from DSL::Inversion

#not

Methods included from DSL::Caller

#[]

Class Attribute Details

.assertionAssertion::Base (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The assertion being inverted.

Returns:



42
43
44
# File 'lib/assertion/inversion.rb', line 42

def assertion
  @assertion
end

Class Method Details

.checkBoolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks the current state of the assertion

Returns:

  • (Boolean)


58
59
60
# File 'lib/assertion/inversion.rb', line 58

def check
  !assertion.check
end

.initialize(assertion) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
36
# File 'lib/assertion/inversion.rb', line 33

def initialize(assertion)
  @assertion = assertion
  IceNine.deep_freeze(self)
end

.message(state = nil) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The translated message describing the state of assertion

Parameters:

  • state (Boolean) (defaults to: nil)

Returns:

  • (String)


50
51
52
# File 'lib/assertion/inversion.rb', line 50

def message(state = nil)
  assertion.message !state
end

.new(assertion) ⇒ Assertion::Inversion

Creates the inversion for the selected assertion object

Parameters:

Returns:



# File 'lib/assertion/inversion.rb', line 24