Class: Vanguard::Evaluator

Inherits:
Object
  • Object
show all
Includes:
AbstractType, Adamantium::Flat
Defined in:
lib/vanguard/evaluator.rb

Overview

Abstract base class for rule evaluators

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule, resource) ⇒ undefined

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 object

Parameters:

  • rule (Rule)
  • resource (Object)


31
32
33
# File 'lib/vanguard/evaluator.rb', line 31

def initialize(rule, resource)
  @rule, @resource = rule, 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.

Return validated resource

Returns:

  • (Object)


12
13
14
# File 'lib/vanguard/evaluator.rb', line 12

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.

Return rule

Returns:



20
21
22
# File 'lib/vanguard/evaluator.rb', line 20

def rule
  @rule
end

Instance Method Details

#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 value to be validated

Returns:

  • (Object)


41
42
43
# File 'lib/vanguard/evaluator.rb', line 41

def value
  resource.public_send(rule.attribute_name)
end

#violationViolation

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 violation

Returns:



52
53
54
# File 'lib/vanguard/evaluator.rb', line 52

def violation
  Violation.new(rule, resource)
end

#violationsEnumerable<Violation>

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 violations

Returns:



63
64
65
66
67
68
69
# File 'lib/vanguard/evaluator.rb', line 63

def violations
  unless valid?
    [violation]
  else
    []
  end
end