Class: Knight::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/knight/error.rb

Overview

A representation of an error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule, resource) ⇒ Error

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize an error

Parameters:

  • rule (Rule)
  • resource (Object)


31
32
33
34
# File 'lib/knight/error.rb', line 31

def initialize(rule, resource)
  @rule = rule
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object under validation

Returns:

  • (Object)


21
22
23
# File 'lib/knight/error.rb', line 21

def resource
  @resource
end

#ruleRule (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Broken rule

Returns:



14
15
16
# File 'lib/knight/error.rb', line 14

def rule
  @rule
end

Instance Method Details

#messageString

Return formatted error message

Examples:

error_message = error.message

Returns:

  • (String)


44
45
46
# File 'lib/knight/error.rb', line 44

def message
  rule.message % rule.to_hash.merge(value: value)
end