class Schematrix::Schema
Predicates shared by the compiler and the generators: what a compiled schema constrains, and whether the constructor demands the property.
Public Class Methods
# File lib/schematrix/visitor.rb, line 106 def self.qualifying_enum_members(values) return unless values.is_a?(Array) members = values.compact.uniq return unless members.size > 1 return unless members.all?(String) || members.all?(Integer) members end
Public Instance Methods
Source
# File lib/schematrix/visitor.rb, line 132 def constructor_required? return false unless required return false unless default.nil? true end
Whether the constructor demands the property: listed in required, with no default to fall back on. A null-typed property still demands the keyword (its value may be nil; the argument may not be omitted), so only this predicate decides the constructor signature and everything that must match it.
Source
# File lib/schematrix/visitor.rb, line 155 def map_shaped? return false unless type.include?(TYPE_OBJECT) return false unless (type - [TYPE_OBJECT, TYPE_NULL]).empty? return false unless ref.nil? return false if intersection return false unless any_of.empty? && one_of.empty? return false if additional_properties.nil? properties.nil? || properties.empty? end
Whether the schemaโs whole shape is a catch-all (an object with no own properties, no ref, no variants, and a non-closed additionalProperties). Such a schema is a plain Hash, not a class: it types as Hash[String, <catch-all value type>] and generates nothing, because a class would only wrap a map and could not be iterated. A closed shape (catch-all nil) is an empty object, not a map, and keeps its class.
Source
# File lib/schematrix/visitor.rb, line 142 def strictly_required? return false if type.include?(TYPE_NULL) constructor_required? end
Whether the constructor demands the property and its type does not admit nil: optional values render nilable wherever they may be absent.
Source
# File lib/schematrix/visitor.rb, line 123 def untyped? type.empty? && ref.nil? && any_of.empty? && one_of.empty? end
Whether the schema constrains nothing: empty type set, no ref, no variants. It types as untyped and is the identity for intersections.