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

#error_list(node = errors.to_h, path = '') ⇒ Object



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

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

#errorsObject



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

def errors
  valid? unless @validation

  @validation.errors
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): #{error_list.join(', ')}"
end