Class: Artificial::Validators::MessageValidator
- Inherits:
-
Object
- Object
- Artificial::Validators::MessageValidator
- Defined in:
- lib/artificial/validators/message_validator.rb
Constant Summary collapse
- VALID_ROLES =
%w[system user assistant].freeze
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #error_messages ⇒ Object
-
#initialize(messages) ⇒ MessageValidator
constructor
A new instance of MessageValidator.
- #valid? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(messages) ⇒ MessageValidator
10 11 12 13 |
# File 'lib/artificial/validators/message_validator.rb', line 10 def initialize() = @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/artificial/validators/message_validator.rb', line 8 def errors @errors end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
8 9 10 |
# File 'lib/artificial/validators/message_validator.rb', line 8 def end |
Instance Method Details
#error_messages ⇒ Object
33 34 35 |
# File 'lib/artificial/validators/message_validator.rb', line 33 def @errors end |
#valid? ⇒ Boolean
28 29 30 31 |
# File 'lib/artificial/validators/message_validator.rb', line 28 def valid? validate if @errors.empty? @errors.empty? end |
#validate ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/artificial/validators/message_validator.rb', line 15 def validate @errors.clear return add_error('Messages must be an array') unless .is_a?(Array) return add_error('Messages array cannot be empty') if .empty? .each_with_index do |, index| (, index) end self end |