Sha256: 65b099666e8d5a8659d393d01b69b9cd2b3e0819184100a8d35888ed7de14a3a
Contents?: true
Size: 1.59 KB
Versions: 9
Compression:
Stored size: 1.59 KB
Contents
module Lurker module Json class Polymorph < Schema def merge!(schema) case parent_schema when Lurker::Json::Object parent_schema[Json::PROPERTIES][parent_property] = @parser.typed.parse(schema) when Lurker::Json::List if schema.is_a?(Array) return if schema.empty? schema = schema.dup parent_schema[Json::ITEMS] = @parser.typed.parse(schema.shift) parent_schema.merge!(schema) else parent_schema[Json::ITEMS] = @parser.typed.parse(schema) end else parent_schema[parent_property] = @parser.typed.parse(schema) end end def replace!(property, schema) morph = Lurker::Json::Object.new({}, subschema_options) case parent_schema when Lurker::Json::Object parent_schema[Json::PROPERTIES][parent_property] = morph parent_schema.replace!(property, schema) when Lurker::Json::List parent_schema[Json::ITEMS] = morph parent_schema.replace!(property, schema) else parent_schema[parent_property] = morph parent_schema.replace!(property, schema) end end private def parse_schema(schema) @schema = schema end # NOTE : The parser will ref to parent_schema instead def subschema_options {uri: parent_schema.uri, root_schema: parent_schema.root? ? parent_schema : parent_schema.root_schema, parent_schema: parent_schema, parent_property: parent_property} end end end end
Version data entries
9 entries across 9 versions & 1 rubygems