This module implements type validation routines that are used by most of the classes in the Copland::Configuration::YAML module.

Public Instance methods
ensure_element_type( name, element, klass )

Ensures that the given element (identified by the given name) is indeed an instance of the given klass. If it is not, a ParserError is raised.

    # File lib/copland/configuration/yaml/utils.rb, line 47
47:         def ensure_element_type( name, element, klass )
48:           unless element.is_a?( klass )
49:             raise ParserError,
50:               "#{name.inspect} must be of type #{klass}, " +
51:               "not #{element.class}",
52:               caller[1..-1]
53:           end
54:         end
validate_elements( hash, path="" )

This requires that the VALID_KEYS and REQUIRED_KEYS constants have been set in the including class. Then, it tests to see if the given hash includes any values other than those that are defined in VALID_KEYS, or whether any keys in REQUIRED_KEYS are missing from hash. If either condition is true, a ParserError is raised. If path is given, it describes the location of the element (for error reporting).

    # File lib/copland/configuration/yaml/utils.rb, line 63
63:         def validate_elements( hash, path="" )
64:           path = " at #{path}" if path
65:           invalid_keys = hash.keys - self.class::VALID_KEYS
66:           unless invalid_keys.empty?
67:             raise ParserError,
68:               "invalid elements(s)#{path}: #{invalid_keys.inspect}"
69:           end
71:           missing_keys = self.class::REQUIRED_KEYS - hash.keys
72:           unless missing_keys.empty?
73:             raise ParserError,
74:               "missing element(s)#{path}: #{missing_keys.inspect}"
75:           end
76:         end