Class: NxtSchema::Template::Schema

Inherits:
Base
  • Object
show all
Includes:
HasSubNodes
Defined in:
lib/nxt_schema/template/schema.rb

Constant Summary collapse

DEFAULT_TYPE =
NxtSchema::Types::Strict::Hash

Instance Attribute Summary

Attributes inherited from Base

#additional_keys_strategy, #configuration, #context, #key_transformer, #maybe_evaluators, #meta, #name, #on_evaluators, #options, #parent_node, #path, #root_node, #type, #type_system, #validations

Instance Method Summary collapse

Methods included from HasSubNodes

#[], #add_sub_node, #any_of, #collection, #ensure_sub_nodes_present, #node, #schema, #sub_nodes

Methods inherited from Base

#apply, #apply!, #build_node, #default, #maybe, #omnipresent?, #on, #optional?, #root_node?, #validate, #validate_with

Constructor Details

#initialize(name:, type: DEFAULT_TYPE, parent_node:, **options, &block) ⇒ Schema

Returns a new instance of Schema.



8
9
10
11
# File 'lib/nxt_schema/template/schema.rb', line 8

def initialize(name:, type: DEFAULT_TYPE, parent_node:, **options, &block)
  super
  ensure_sub_nodes_present
end

Instance Method Details

#omnipresent(name, node_or_type_of_node, **options, &block) ⇒ Object



17
18
19
# File 'lib/nxt_schema/template/schema.rb', line 17

def omnipresent(name, node_or_type_of_node, **options, &block)
  node(name, node_or_type_of_node, **options.merge(omnipresent: true), &block)
end

#optional(name, node_or_type_of_node, **options, &block) ⇒ Object



13
14
15
# File 'lib/nxt_schema/template/schema.rb', line 13

def optional(name, node_or_type_of_node, **options, &block)
  node(name, node_or_type_of_node, **options.merge(optional: true), &block)
end