module NxtSchema::Template::HasSubNodes
Public Instance Methods
[](key)
click to toggle source
# File lib/nxt_schema/template/has_sub_nodes.rb, line 76 def [](key) sub_nodes[key] end
add_sub_node(node)
click to toggle source
# File lib/nxt_schema/template/has_sub_nodes.rb, line 67 def add_sub_node(node) sub_nodes.add(node) node end
any_of(name, **options, &block)
click to toggle source
# File lib/nxt_schema/template/has_sub_nodes.rb, line 30 def any_of(name, **options, &block) node = NxtSchema::Template::AnyOf.new( name: name, parent_node: self, **options, &block ) add_sub_node(node) end
collection(name, type = NxtSchema::Template::Collection::DEFAULT_TYPE, **options, &block)
click to toggle source
# File lib/nxt_schema/template/has_sub_nodes.rb, line 4 def collection(name, type = NxtSchema::Template::Collection::DEFAULT_TYPE, **options, &block) node = NxtSchema::Template::Collection.new( name: name, type: type, parent_node: self, **options, &block ) add_sub_node(node) end
Also aliased as: nodes
ensure_sub_nodes_present()
click to toggle source
# File lib/nxt_schema/template/has_sub_nodes.rb, line 80 def ensure_sub_nodes_present return if sub_nodes.any? raise NxtSchema::Errors::InvalidOptions, "#{self.class.name} must have sub nodes" end
node(name, node_or_type_of_node, **options, &block)
click to toggle source
# File lib/nxt_schema/template/has_sub_nodes.rb, line 41 def node(name, node_or_type_of_node, **options, &block) node = if node_or_type_of_node.is_a?(NxtSchema::Template::Base) raise ArgumentError, "Can't provide a block along with a node" if block.present? node_or_type_of_node.class.new( name: name, type: node_or_type_of_node.type, parent_node: self, **node_or_type_of_node.options.merge(options), &node_or_type_of_node.configuration ) else NxtSchema::Template::Leaf.new( name: name, type: node_or_type_of_node, parent_node: self, **options, &block ) end add_sub_node(node) end
Also aliased as: required
nodes(name, type = NxtSchema::Template::Collection::DEFAULT_TYPE, **options, &block)
Alias for: collection
schema(name, type = NxtSchema::Template::Schema::DEFAULT_TYPE, **options, &block)
click to toggle source
# File lib/nxt_schema/template/has_sub_nodes.rb, line 18 def schema(name, type = NxtSchema::Template::Schema::DEFAULT_TYPE, **options, &block) node = NxtSchema::Template::Schema.new( name: name, type: type, parent_node: self, **options, &block ) add_sub_node(node) end
sub_nodes()
click to toggle source
# File lib/nxt_schema/template/has_sub_nodes.rb, line 72 def sub_nodes @sub_nodes ||= Template::SubNodes.new end