Class: NxtSchema::Template::SubNodes

Inherits:
Hash
  • Object
show all
Defined in:
lib/nxt_schema/template/sub_nodes.rb

Instance Method Summary collapse

Constructor Details

#initializeSubNodes

Returns a new instance of SubNodes.



4
5
6
7
# File 'lib/nxt_schema/template/sub_nodes.rb', line 4

def initialize
  super
  transform_keys { |k| k.to_sym }
end

Instance Method Details

#add(node) ⇒ Object



9
10
11
12
13
# File 'lib/nxt_schema/template/sub_nodes.rb', line 9

def add(node)
  node_name = node.name
  ensure_node_name_free(node_name)
  self[node_name] = node
end

#ensure_node_name_free(name) ⇒ Object

Raises:

  • (KeyError)


15
16
17
18
19
# File 'lib/nxt_schema/template/sub_nodes.rb', line 15

def ensure_node_name_free(name)
  return unless key?(name)

  raise KeyError, "Node with name '#{name}' already exists! Node names must be unique!"
end