Class: Parametric::OneOf
- Inherits:
-
Object
- Object
- Parametric::OneOf
- Defined in:
- lib/parametric/one_of.rb
Overview
Policy that validates a value against multiple schemas and chooses the first valid match.
OneOf is useful for polymorphic validation where a field can be one of several different object structures. It tries each schema in order and returns the output of the first schema that successfully validates the input.
Defined Under Namespace
Classes: Runner
Instance Method Summary collapse
-
#build(key, value, payload:, context:) ⇒ Runner
Build a Runner instance for this policy (PolicyFactory interface).
-
#initialize(schemas = []) ⇒ OneOf
constructor
Initialize with an array of schemas to validate against.
-
#meta_data ⇒ Hash
Return metadata about this policy.
Constructor Details
#initialize(schemas = []) ⇒ OneOf
Initialize with an array of schemas to validate against
30 31 32 |
# File 'lib/parametric/one_of.rb', line 30 def initialize(schemas = []) @schemas = schemas end |
Instance Method Details
#build(key, value, payload:, context:) ⇒ Runner
Build a Runner instance for this policy (PolicyFactory interface)
41 42 43 |
# File 'lib/parametric/one_of.rb', line 41 def build(key, value, payload:, context:) Runner.new(@schemas, key, value, payload, context) end |
#meta_data ⇒ Hash
Return metadata about this policy
48 49 50 |
# File 'lib/parametric/one_of.rb', line 48 def { type: :object, schema: @schemas } end |