Module: Pedicel::Validator::InstanceMethods
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
285 286 287 |
# File 'lib/pedicel/validator.rb', line 285 def output @output end |
Instance Method Details
#errors ⇒ Object
303 304 305 306 307 |
# File 'lib/pedicel/validator.rb', line 303 def errors valid? unless @validation @validation.errors.to_h.sort end |
#errors_formatted(node = [errors]) ⇒ Object
309 310 311 312 313 314 315 316 317 |
# File 'lib/pedicel/validator.rb', line 309 def errors_formatted(node = [errors]) node.pop.flat_map do |key, value| if value.is_a?(Array) value.map { |error| "#{(node + [key]).join('.')} #{error}" } else errors_formatted(node + [key, value]) end end end |
#valid? ⇒ Boolean
297 298 299 300 301 |
# File 'lib/pedicel/validator.rb', line 297 def valid? validate rescue Error false end |
#validate ⇒ Object
287 288 289 290 291 292 293 294 295 |
# File 'lib/pedicel/validator.rb', line 287 def validate @validation ||= @schema.call(@input) @output = @validation.to_h return true if @validation.success? raise Error, "validation error: #{@validation.errors.to_h.keys.join(', ')}" end |