Class: Parametric::TaggedOneOf::Runner
- Inherits:
-
Object
- Object
- Parametric::TaggedOneOf::Runner
- Defined in:
- lib/parametric/tagged_one_of.rb
Instance Method Summary collapse
-
#eligible? ⇒ Boolean
Should this policy run at all? returning [false] halts the field policy chain.
-
#initialize(index, matchers, key, value, payload, context) ⇒ Runner
constructor
A new instance of Runner.
-
#message ⇒ String
Error message for this policy.
-
#valid? ⇒ Boolean
If [false], add [#message] to result errors and halt processing field.
-
#value ⇒ Any
Coerce the value, or return as-is.
Constructor Details
#initialize(index, matchers, key, value, payload, context) ⇒ Runner
Returns a new instance of Runner.
89 90 91 92 93 94 95 96 |
# File 'lib/parametric/tagged_one_of.rb', line 89 def initialize(index, matchers, key, value, payload, context) @matchers = matchers @key = key @raw_value = value @payload = payload @context = context @index_value = index.call(payload) end |
Instance Method Details
#eligible? ⇒ Boolean
Should this policy run at all? returning [false] halts the field policy chain.
101 102 103 |
# File 'lib/parametric/tagged_one_of.rb', line 101 def eligible? true end |
#message ⇒ String
Error message for this policy
119 120 121 |
# File 'lib/parametric/tagged_one_of.rb', line 119 def "#{@value} is invalid. No sub-schema found for '#{@index_value}'" end |
#valid? ⇒ Boolean
If [false], add [#message] to result errors and halt processing field.
107 108 109 |
# File 'lib/parametric/tagged_one_of.rb', line 107 def valid? has_sub_schema? end |
#value ⇒ Any
Coerce the value, or return as-is.
113 114 115 |
# File 'lib/parametric/tagged_one_of.rb', line 113 def value @value ||= has_sub_schema? ? sub_schema.coerce(@raw_value, @key, @context) : @raw_value end |