Class: Parametric::PolicyAdapter::PolicyRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/parametric/policy_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(policy, key, value, payload, context) ⇒ PolicyRunner

Returns a new instance of PolicyRunner.



7
8
9
# File 'lib/parametric/policy_adapter.rb', line 7

def initialize(policy, key, value, payload, context)
  @policy, @key, @raw_value, @payload, @context = policy, key, value, payload, context
end

Instance Method Details

#eligible?Boolean

The PolicyRunner interface

Returns:

  • (Boolean)


13
14
15
# File 'lib/parametric/policy_adapter.rb', line 13

def eligible?
  @policy.eligible?(@raw_value, @key, @payload)
end

#include_non_eligible_in_ouput?Boolean

If a policy is not #eligible?, use this to decide if its key should still be included in output hash.

Returns:

  • (Boolean)


21
22
23
# File 'lib/parametric/policy_adapter.rb', line 21

def include_non_eligible_in_ouput?
  false
end

#messageString

Returns:

  • (String)


36
37
38
# File 'lib/parametric/policy_adapter.rb', line 36

def message
  @policy.message
end

#valid?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/parametric/policy_adapter.rb', line 26

def valid?
  @policy.valid?(value, @key, @payload)
end

#valueAny

Returns:

  • (Any)


31
32
33
# File 'lib/parametric/policy_adapter.rb', line 31

def value
  @value ||= @policy.coerce(@raw_value, @key, @context)
end