Module: Schematist::DSL::Utilities
- Included in:
- Schematist::DSL
- Defined in:
- lib/schematist/dsl/utilities.rb
Instance Method Summary collapse
-
#define(name) ⇒ Object
Schema definition and reference methods.
-
#keys(&block) ⇒ Object
Constrains every property name, as JSON Schema propertyNames.
-
#keys_matching(pattern, &block) ⇒ Object
Constrains the names of properties matching a pattern, as JSON Schema patternProperties.
- #object_keywords ⇒ Object
- #reference(schema_name) ⇒ Object
Instance Method Details
#define(name) ⇒ Object
Schema definition and reference methods
7 8 9 10 11 12 |
# File 'lib/schematist/dsl/utilities.rb', line 7 def define(name, &) sub_schema = Class.new(Schema) sub_schema.class_eval(&) definitions[name] = schema_for(sub_schema) end |
#keys(&block) ⇒ Object
Constrains every property name, as JSON Schema propertyNames
27 28 29 |
# File 'lib/schematist/dsl/utilities.rb', line 27 def keys(&block) object_keywords[:propertyNames] = collect_schemas_from_block(&block).first end |
#keys_matching(pattern, &block) ⇒ Object
Constrains the names of properties matching a pattern, as JSON Schema patternProperties
19 20 21 22 23 24 |
# File 'lib/schematist/dsl/utilities.rb', line 19 def keys_matching(pattern, &block) pattern = pattern.source if pattern.is_a?(Regexp) object_keywords[:patternProperties] ||= {} object_keywords[:patternProperties][pattern] = collect_schemas_from_block(&block).first end |
#object_keywords ⇒ Object
14 15 16 |
# File 'lib/schematist/dsl/utilities.rb', line 14 def object_keywords @object_keywords ||= {} end |
#reference(schema_name) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/schematist/dsl/utilities.rb', line 31 def reference(schema_name) if schema_name == :root {"$ref" => "#"} else {"$ref" => "#/$defs/#{schema_name}"} end end |