Module: JSON::SchemaDsl
- Included in:
- Proxy
- Defined in:
- lib/json/schema_dsl.rb,
lib/json/schema_dsl/null.rb,
lib/json/schema_dsl/array.rb,
lib/json/schema_dsl/proxy.rb,
lib/json/schema_dsl/types.rb,
lib/json/schema_dsl/entity.rb,
lib/json/schema_dsl/object.rb,
lib/json/schema_dsl/string.rb,
lib/json/schema_dsl/boolean.rb,
lib/json/schema_dsl/builder.rb,
lib/json/schema_dsl/integer.rb,
lib/json/schema_dsl/numeric.rb,
lib/json/schema_dsl/ast_node.rb,
lib/json/schema_dsl/renderer.rb,
lib/json/schema_dsl/configuration.rb,
lib/json/schema_dsl/renderers/base.rb,
lib/json/schema_dsl/renderers/alias.rb,
lib/json/schema_dsl/renderers/filter.rb,
lib/json/schema_dsl/renderers/desugar.rb,
lib/json/schema_dsl/renderers/multiplexer.rb
Overview
This module provides the base that it includes with the methods to build new json-schemas.
Defined Under Namespace
Modules: AstNode, Renderers Classes: Array, Boolean, Builder, Configuration, Entity, Error, Integer, Null, Number, Numeric, Object, Proxy, Renderer, String, Types
Constant Summary collapse
- DEFAULT_TYPES =
JSON::SchemaDsl::Entity .descendants.dup.push(JSON::SchemaDsl::Entity).freeze
- DEFAULT_RENDERERS =
[Renderers::Desugar, Renderers::Multiplexer, Renderers::Alias, Renderers::Filter].freeze
Class Attribute Summary collapse
-
.registered_renderers ⇒ Array<Class>
The renderer classes that schema_dsl will use in the renderer.
Class Method Summary collapse
-
.define_schema_dsl! ⇒ Object
Defines the dsl for all registered types.
-
.define_type_methods(type) ⇒ Object
Defines builder methods for the given type.
-
.proxy ⇒ JSON::SchemaDsl::Proxy
A new proxy to build schemas.
-
.register_type(type) ⇒ Array<Class>
The registered types.
-
.registered_types ⇒ Array<Class>
The registered types.
-
.reset! ⇒ Object
Reset all settings to default.
-
.reset_registered_renderers! ⇒ Array<Class>
Resets the registered_renderers to the default settings.
-
.reset_schema_dsl! ⇒ Object
Resets schema_dsl back to default.
-
.type_method_name(type) ⇒ String
The name of the new method.
-
.type_methods ⇒ Array<Symbol>
An array of all type methods.
Class Attribute Details
.registered_renderers ⇒ Array<Class>
Returns The renderer classes that schema_dsl will use in the renderer.
44 45 46 |
# File 'lib/json/schema_dsl.rb', line 44 def registered_renderers @registered_renderers ||= DEFAULT_RENDERERS.dup end |
Class Method Details
.define_schema_dsl! ⇒ Object
Defines the dsl for all registered types.
76 77 78 |
# File 'lib/json/schema_dsl.rb', line 76 def define_schema_dsl! registered_types.map { |t| define_type_methods(t) } end |
.define_type_methods(type) ⇒ Object
Defines builder methods for the given type.
82 83 84 85 86 87 88 |
# File 'lib/json/schema_dsl.rb', line 82 def define_type_methods(type) JSON::SchemaDsl::Builder.define_builder_method(type) builder = JSON::SchemaDsl::Builder[type] define_method(type_method_name(type)) do |name = nil, **attributes, &block| builder.build(name, **attributes, scope: self, &block) end end |
.proxy ⇒ JSON::SchemaDsl::Proxy
Returns a new proxy to build schemas.
98 99 100 |
# File 'lib/json/schema_dsl.rb', line 98 def proxy ::JSON::SchemaDsl::Proxy.new end |
.register_type(type) ⇒ Array<Class>
Returns The registered types.
63 64 65 |
# File 'lib/json/schema_dsl.rb', line 63 def register_type(type) registered_types.push(type).tap { define_type_methods(type) } end |
.registered_types ⇒ Array<Class>
Returns The registered types. These are used to add new dsl and builder methods.
56 57 58 |
# File 'lib/json/schema_dsl.rb', line 56 def registered_types @registered_types ||= DEFAULT_TYPES.dup end |
.reset! ⇒ Object
Reset all settings to default.
91 92 93 94 95 |
# File 'lib/json/schema_dsl.rb', line 91 def reset! reset_registered_renderers! reset_type_defaults! reset_schema_dsl! end |
.reset_registered_renderers! ⇒ Array<Class>
Resets the registered_renderers to the default settings
50 51 52 |
# File 'lib/json/schema_dsl.rb', line 50 def reset_registered_renderers! @registered_renderers = DEFAULT_RENDERERS.dup end |
.reset_schema_dsl! ⇒ Object
Resets schema_dsl back to default. Removes all dsl methods and redefines
them with the default types.
69 70 71 72 73 |
# File 'lib/json/schema_dsl.rb', line 69 def reset_schema_dsl! type_methods.each { |tm| remove_method tm } @registered_types = DEFAULT_TYPES.dup define_schema_dsl! end |
.type_method_name(type) ⇒ String
Returns the name of the new method.
109 110 111 |
# File 'lib/json/schema_dsl.rb', line 109 def type_method_name(type) type.type_method_name || 'entity' end |
.type_methods ⇒ Array<Symbol>
Returns An array of all type methods.
103 104 105 |
# File 'lib/json/schema_dsl.rb', line 103 def type_methods registered_types.map { |t| type_method_name(t).to_sym } & instance_methods end |