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

#attribute_nameString

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.

Return error attribute name

Returns:

  • (String)


53
54
55
# File 'lib/knight/error.rb', line 53

def attribute_name
  rule.attribute_name
end

#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

#valueObject

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.

Return error value

Returns:

  • (Object)


62
63
64
# File 'lib/knight/error.rb', line 62

def value
  resource.public_send(attribute_name) if resource.respond_to?(attribute_name)
end