Sha256: e4a6163182b7609ff2823ca56c10354702a2408da63097f68cf257451f7e2ba9

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8

module Assertion

  # Describes the inversion of the assertion object
  #
  # The inversion decorates the source assertion switching its message
  # (from wrong to right) and reverting its `check`.
  #
  # @example
  #   Adult = Assertion.about :name, :age do
  #     age >= 18
  #   end
  #
  #   assertion = Adult.new
  #   inversion = Inversion.new(assertion)
  #
  #   assertion.call.valid? == inversion.call.invalid? # => true
  #
  # @api private
  #
  class Inversion < Base

    # @!scope class
    # @!method new(assertion)
    # Creates the inversion for the selected assertion object
    #
    # @param [Assertion::Base] assertion The assertion being inverted
    #
    # @return [Assertion::Inversion]

    # @private
    def initialize(assertion)
      @assertion = assertion
      freeze
    end

    # @!attribute [r] assertion
    #
    # @return [Assertion::Base] The assertion being inverted
    #
    attr_reader :assertion

    # The translated message describing the state of assertion
    #
    # @param [Boolean] state
    #
    # @return [String]
    #
    def message(state = nil)
      assertion.message(!state)
    end

    # Checks the current state of the assertion
    #
    # @return [Boolean]
    #
    def check
      !assertion.check
    end

  end # class Inversion

end # module Assertion

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
assertion-0.0.1 lib/assertion/inversion.rb