Class: Parametric::Wrapper::Runner
- Inherits:
-
Object
- Object
- Parametric::Wrapper::Runner
- Defined in:
- lib/parametric/wrapper.rb
Overview
Policy runner that executes the wrapper’s coercion and validation logic.
This class implements the policy runner interface required by Parametric’s policy system. It delegates coercion to the wrapper object and collects validation errors from the coerced value.
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#eligible? ⇒ Boolean
Check if this policy should run.
-
#initialize(caster, key, value) ⇒ Runner
constructor
Initialize the runner with coercion logic.
-
#message ⇒ String
Generate a human-readable error message from validation errors.
-
#valid? ⇒ Boolean
Check if the coerced value is valid.
Constructor Details
#initialize(caster, key, value) ⇒ Runner
Initialize the runner with coercion logic.
77 78 79 80 81 82 |
# File 'lib/parametric/wrapper.rb', line 77 def initialize(caster, key, value) @caster = caster @key = key @value = caster.coerce(value) @errors = @value.errors end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
70 71 72 |
# File 'lib/parametric/wrapper.rb', line 70 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
70 71 72 |
# File 'lib/parametric/wrapper.rb', line 70 def value @value end |
Instance Method Details
#eligible? ⇒ Boolean
Check if this policy should run.
87 88 89 |
# File 'lib/parametric/wrapper.rb', line 87 def eligible? true end |
#message ⇒ String
Generate a human-readable error message from validation errors.
99 |
# File 'lib/parametric/wrapper.rb', line 99 def = @errors.map { |k, v| "#{k} #{v.join(', ')}" }.join('. ') |
#valid? ⇒ Boolean
Check if the coerced value is valid.
94 |
# File 'lib/parametric/wrapper.rb', line 94 def valid? = @errors.empty? |