Module: NxtSchema::Node::HasSubNodes
- Included in:
- Collection, Constructor, Schema
- Defined in:
- lib/nxt_schema/node/has_subnodes.rb
Instance Attribute Summary collapse
-
#template_store ⇒ Object
Returns the value of attribute template_store.
-
#value_store ⇒ Object
Returns the value of attribute value_store.
Instance Method Summary collapse
- #dup ⇒ Object
-
#node(name, type_or_node, **options, &block) ⇒ Object
TODO: Would be cool if we could register custom node types!.
- #nodes(name, **options, &block) ⇒ Object (also: #array)
- #required(name, type, **options, &block) ⇒ Object (also: #requires)
- #schema(name, **options, &block) ⇒ Object (also: #hash)
- #struct(name, **options, &block) ⇒ Object
Instance Attribute Details
#template_store ⇒ Object
Returns the value of attribute template_store.
9 10 11 |
# File 'lib/nxt_schema/node/has_subnodes.rb', line 9 def template_store @template_store end |
#value_store ⇒ Object
Returns the value of attribute value_store.
9 10 11 |
# File 'lib/nxt_schema/node/has_subnodes.rb', line 9 def value_store @value_store end |
Instance Method Details
#dup ⇒ Object
75 76 77 78 79 80 |
# File 'lib/nxt_schema/node/has_subnodes.rb', line 75 def dup result = super result.template_store = template_store.deep_dup result. = .deep_dup result end |
#node(name, type_or_node, **options, &block) ⇒ Object
TODO: Would be cool if we could register custom node types!
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nxt_schema/node/has_subnodes.rb', line 12 def node(name, type_or_node, **, &block) child_node = case type_or_node.to_s.to_sym when :Schema NxtSchema::Node::Schema.new(name: name, type: NxtSchema::Types::Strict::Hash, parent_node: self, **, &block) when :Collection NxtSchema::Node::Collection.new(name: name, type: NxtSchema::Types::Strict::Array, parent_node: self, **, &block) when :Struct NxtSchema::Node::Constructor.new( name: name, type: NxtSchema::Types::Constructor(::Struct) { |hash| ::Struct.new(*hash.keys).new(*hash.values) }, parent_node: self, **, &block ) when :OpenStruct NxtSchema::Node::Constructor.new( name: name, type: NxtSchema::Types::Constructor(::OpenStruct), parent_node: self, **, &block ) else if type_or_node.is_a?(NxtSchema::Node::Base) node = type_or_node.clone node..merge!() node.name = name node.parent_node = self node else NxtSchema::Node::Leaf.new(name: name, type: type_or_node, parent_node: self, **) end end # TODO: Should we check if there is a raise KeyError, "Duplicate registration for key: #{name}" if template_store.key?(name) template_store.push(child_node) child_node end |
#nodes(name, **options, &block) ⇒ Object Also known as: array
59 60 61 |
# File 'lib/nxt_schema/node/has_subnodes.rb', line 59 def nodes(name, **, &block) node(name, :Collection, , &block) end |
#required(name, type, **options, &block) ⇒ Object Also known as: requires
53 54 55 |
# File 'lib/nxt_schema/node/has_subnodes.rb', line 53 def required(name, type, **, &block) node(name, type, , &block) end |
#schema(name, **options, &block) ⇒ Object Also known as: hash
65 66 67 |
# File 'lib/nxt_schema/node/has_subnodes.rb', line 65 def schema(name, **, &block) node(name, :Schema, , &block) end |