Class: Assertion::State
- Inherits:
-
Object
- Object
- Assertion::State
- Defined in:
- lib/assertion/state.rb
Overview
Describes the state of the assertion applied to given arguments (the result of the checkup)
Class Attribute Summary collapse
-
.messages ⇒ Array<String>
readonly
Error messages.
Class Method Summary collapse
-
.&(other) ⇒ Assertion::State
(also: >>, +)
Composes the state with the other state.
- .initialize(state, *messages) ⇒ Object
-
.invalid? ⇒ Boolean
Check whether a stated assertion is not satisfied by its attributes.
-
.new(state, *messages) ⇒ Assertion::State
Creates the immutable state instance with a corresponding error messages.
-
.valid? ⇒ Boolean
Check whether a stated assertion is satisfied by its attributes.
-
.validate! ⇒ true
Check whether a stated assertion is satisfied by its attributes.
Class Attribute Details
.messages ⇒ Array<String> (readonly)
Returns error messages.
32 33 34 |
# File 'lib/assertion/state.rb', line 32 def @messages end |
Class Method Details
.&(other) ⇒ Assertion::State Also known as: >>, +
Composes the state with the other state
71 72 73 |
# File 'lib/assertion/state.rb', line 71 def &(other) self.class.new(valid? & other.valid?, + other.) end |
.initialize(state, *messages) ⇒ Object
22 23 24 25 26 |
# File 'lib/assertion/state.rb', line 22 def initialize(state, *) @state = state @messages = (state ? [] : .flatten.uniq).freeze freeze end |
.invalid? ⇒ Boolean
Check whether a stated assertion is not satisfied by its attributes
46 47 48 |
# File 'lib/assertion/state.rb', line 46 def invalid? !@state end |
.new(state, *messages) ⇒ Assertion::State
Creates the immutable state instance with a corresponding error messages
|
# File 'lib/assertion/state.rb', line 12
|
.valid? ⇒ Boolean
Check whether a stated assertion is satisfied by its attributes
38 39 40 |
# File 'lib/assertion/state.rb', line 38 def valid? !invalid? end |
.validate! ⇒ true
Check whether a stated assertion is satisfied by its attributes
57 58 59 |
# File 'lib/assertion/state.rb', line 57 def validate! invalid? ? fail(InvalidError.new ) : true end |