Module: Aliquot::Validator::InstanceMethods
- Included in:
- EncryptedMessageValidator, PaymentMethodDetailsValidator, SignedKeyValidator, SignedMessage, Token
- Defined in:
- lib/aliquot/validator.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #error_list(node = errors.to_h, path = '') ⇒ Object
- #errors ⇒ Object
- #valid? ⇒ Boolean
- #validate ⇒ Object
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
254 255 256 |
# File 'lib/aliquot/validator.rb', line 254 def output @output end |
Instance Method Details
#error_list(node = errors.to_h, path = '') ⇒ Object
275 276 277 278 279 280 281 282 |
# File 'lib/aliquot/validator.rb', line 275 def error_list(node = errors.to_h, path = '') if node.is_a?(Array) node.map { |error| "#{path} #{error}" } elsif node.is_a?(Hash) path = "#{path}." unless path.empty? node.flat_map { |key, sub_node| error_list(sub_node, "#{path}#{key}") } end end |
#errors ⇒ Object
269 270 271 272 273 |
# File 'lib/aliquot/validator.rb', line 269 def errors valid? unless @validation @validation.errors end |
#valid? ⇒ Boolean
263 264 265 266 267 |
# File 'lib/aliquot/validator.rb', line 263 def valid? validate rescue false end |
#validate ⇒ Object
256 257 258 259 260 261 |
# File 'lib/aliquot/validator.rb', line 256 def validate @validation ||= @schema.call(@input) @output = @validation.to_h return true if @validation.success? raise Aliquot::ValidationError, "validation error(s): #{error_list.join(', ')}" end |