Class: AnyVali::IntersectionSchema
- Defined in:
- lib/anyvali/schemas/intersection_schema.rb
Constant Summary
Constants inherited from Schema
Schema::RESERVED_METADATA_KEYS
Instance Attribute Summary collapse
-
#all_of_schemas ⇒ Object
readonly
Returns the value of attribute all_of_schemas.
Attributes inherited from Schema
#coerce_config, #constraints, #custom_validators, #default_value, #has_default, #kind, #metadata
Instance Method Summary collapse
-
#initialize(all_of:, **kwargs) ⇒ IntersectionSchema
constructor
A new instance of IntersectionSchema.
- #safe_parse(input, path: [], context: nil) ⇒ Object
- #to_node ⇒ Object
Methods inherited from Schema
#coerce, #default, #describe, #export, #parse, #portable?, #refine, type_name, #with_metadata
Constructor Details
#initialize(all_of:, **kwargs) ⇒ IntersectionSchema
Returns a new instance of IntersectionSchema.
7 8 9 10 |
# File 'lib/anyvali/schemas/intersection_schema.rb', line 7 def initialize(all_of:, **kwargs) @all_of_schemas = all_of.freeze super(kind: "intersection", **kwargs) end |
Instance Attribute Details
#all_of_schemas ⇒ Object (readonly)
Returns the value of attribute all_of_schemas.
5 6 7 |
# File 'lib/anyvali/schemas/intersection_schema.rb', line 5 def all_of_schemas @all_of_schemas end |
Instance Method Details
#safe_parse(input, path: [], context: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/anyvali/schemas/intersection_schema.rb', line 18 def safe_parse(input, path: [], context: nil) context ||= ValidationContext.new all_issues = [] merged_output = nil @all_of_schemas.each do |schema| result = schema.safe_parse(input, path: path, context: context) if result.failure? all_issues.concat(result.issues) else if merged_output.nil? merged_output = result.value elsif merged_output.is_a?(Hash) && result.value.is_a?(Hash) merged_output = merged_output.merge(result.value) else merged_output = result.value end end end if all_issues.empty? ParseResult.new(value: merged_output, issues: []) else ParseResult.new(value: nil, issues: all_issues) end end |
#to_node ⇒ Object
12 13 14 15 16 |
# File 'lib/anyvali/schemas/intersection_schema.rb', line 12 def to_node node = super node["allOf"] = @all_of_schemas.map(&:to_node) node end |