Class: RSMP::Validation
- Inherits:
-
Data
- Object
- Data
- RSMP::Validation
- Defined in:
- lib/rsmp/validation.rb
Overview
The result of validating a message against one or more schemas.
Instance Attribute Summary collapse
-
#violations ⇒ Object
readonly
Returns the value of attribute violations.
Instance Method Summary collapse
-
#initialize(violations: []) ⇒ Validation
constructor
A new instance of Validation.
- #invalid? ⇒ Boolean
- #message ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(violations: []) ⇒ Validation
Returns a new instance of Validation.
4 5 6 7 8 |
# File 'lib/rsmp/validation.rb', line 4 def initialize(violations: []) raise ArgumentError, 'violations must be an Array' unless violations.is_a?(Array) super(violations: violations.map { |violation| Array(violation).dup.freeze }.freeze) end |
Instance Attribute Details
#violations ⇒ Object (readonly)
Returns the value of attribute violations
3 4 5 |
# File 'lib/rsmp/validation.rb', line 3 def violations @violations end |
Instance Method Details
#invalid? ⇒ Boolean
14 15 16 |
# File 'lib/rsmp/validation.rb', line 14 def invalid? !valid? end |
#message ⇒ Object
18 19 20 |
# File 'lib/rsmp/validation.rb', line 18 def violations.map { |item| item.reject { |part| part == '' } }.compact.join(', ').strip end |
#valid? ⇒ Boolean
10 11 12 |
# File 'lib/rsmp/validation.rb', line 10 def valid? violations.empty? end |