class Assertion::State

Describes the composable state of the assertion

@api public

Attributes

messages[R]

@!attribute [r] messages

@return [Array<String>] error messages

Public Class Methods

new(state, *messages) click to toggle source

@private

# File lib/assertion/state.rb, line 21
def initialize(state, *messages)
  @state = state
  @messages = state ? [] : messages.flatten.uniq
  IceNine.deep_freeze(self)
end

Public Instance Methods

&(other) click to toggle source

Composes the state with the other state

@param [Assertion::State] other

@return [Assertion::State]

The composed state that carries messages from both the states

@alias >> @alias +

# File lib/assertion/state.rb, line 70
def &(other)
  self.class.new(valid? & other.valid?, messages + other.messages)
end
Also aliased as: >>, +
+(other)
Alias for: &
>>(other)
Alias for: &
invalid?() click to toggle source

Check whether a stated assertion is not satisfied by its attributes

@return [Boolean]

# File lib/assertion/state.rb, line 45
def invalid?
  !@state
end
valid?() click to toggle source

Check whether a stated assertion is satisfied by its attributes

@return [Boolean]

# File lib/assertion/state.rb, line 37
def valid?
  !invalid?
end
validate!() click to toggle source

Check whether a stated assertion is satisfied by its attributes

@return [true]

@raise [Assertion::InvalidError]

When an assertion is not satisfied (validation fails)
# File lib/assertion/state.rb, line 56
def validate!
  invalid? ? fail(InvalidError.new messages) : true
end