Class: Parametric::TaggedOneOf::Runner

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

Instance Method Summary collapse

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.

Returns:

  • (Boolean)


101
102
103
# File 'lib/parametric/tagged_one_of.rb', line 101

def eligible?
  true
end

#messageString

Error message for this policy

Returns:

  • (String)


119
120
121
# File 'lib/parametric/tagged_one_of.rb', line 119

def message
  "#{@value} is invalid. No sub-schema found for '#{@index_value}'"
end

#valid?Boolean

If [false], add [#message] to result errors and halt processing field.

Returns:

  • (Boolean)


107
108
109
# File 'lib/parametric/tagged_one_of.rb', line 107

def valid?
  has_sub_schema?
end

#valueAny

Coerce the value, or return as-is.

Returns:

  • (Any)


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