Module: Aliquot::Validator::InstanceMethods

Included in:
EncryptedMessageValidator, SignedKeyValidator, SignedMessage, Token
Defined in:
lib/aliquot/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#outputObject (readonly)

Returns the value of attribute output.



223
224
225
# File 'lib/aliquot/validator.rb', line 223

def output
  @output
end

Instance Method Details

#errorsObject



238
239
240
241
242
# File 'lib/aliquot/validator.rb', line 238

def errors
  valid? unless @validation

  @validation.errors
end

#errors_formatted(node = [errors]) ⇒ Object



244
245
246
247
248
249
250
251
252
# File 'lib/aliquot/validator.rb', line 244

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

Returns:

  • (Boolean)


232
233
234
235
236
# File 'lib/aliquot/validator.rb', line 232

def valid?
  validate
rescue
  false
end

#validateObject



225
226
227
228
229
230
# File 'lib/aliquot/validator.rb', line 225

def validate
  @validation ||= @schema.call(@input)
  @output = @validation.to_h
  return true if @validation.success?
  raise Aliquot::ValidationError, "validation error(s), #{errors_formatted}"
end