lib/schemacop/v3/one_of_node.rb in schemacop-3.0.10 vs lib/schemacop/v3/one_of_node.rb in schemacop-3.0.11

- old
+ new

@@ -3,11 +3,33 @@ class OneOfNode < CombinationNode def type :oneOf end + def self.allowed_options + super + %i[treat_blank_as_nil] + end + + def cast(value) + item = match(value) + + unless item + if options[:treat_blank_as_nil] && value.blank? && !value.is_a?(FalseClass) + return nil + else + return value + end + end + + return item.cast(value) + end + def _validate(data, result:) - super_data = super + if options[:treat_blank_as_nil] && data.blank? && !data.is_a?(FalseClass) + data = nil + end + + super_data = super(data, result: result) return if super_data.nil? matches = matches(super_data) if matches.size == 1