Class: Parametric::Wrapper::Runner

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(caster, key, value) ⇒ Runner

Initialize the runner with coercion logic.

Parameters:

  • caster (Object)

    Object that responds to ‘coerce(value)`

  • key (Symbol)

    The field key being processed

  • value (Object)

    The input value to be coerced and validated



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

#keyObject (readonly)

Returns the value of attribute key.



70
71
72
# File 'lib/parametric/wrapper.rb', line 70

def key
  @key
end

#valueObject (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.

Returns:

  • (Boolean)

    Always returns true for wrapper policies



87
88
89
# File 'lib/parametric/wrapper.rb', line 87

def eligible?
  true
end

#messageString

Generate a human-readable error message from validation errors.

Returns:

  • (String)

    Formatted error message combining all validation errors



99
# File 'lib/parametric/wrapper.rb', line 99

def message = @errors.map { |k, v| "#{k} #{v.join(', ')}" }.join('. ')

#valid?Boolean

Check if the coerced value is valid.

Returns:

  • (Boolean)

    True if no validation errors, false otherwise



94
# File 'lib/parametric/wrapper.rb', line 94

def valid? = @errors.empty?