Sha256: b06833243c882d6c384e96edb2d0dc198dcde1fc5883b7f5b4599b705306e8f4

Contents?: true

Size: 472 Bytes

Versions: 1

Compression:

Stored size: 472 Bytes

Contents

module NxtSchema
  module Node
    class SubNodes < ::Hash
      def initialize
        super
        transform_keys { |k| k.to_sym }
      end

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nxt_schema-1.0.0 lib/nxt_schema/node/sub_nodes.rb