Class: Vcloud::Core::ConfigValidator
- Inherits:
-
Object
- Object
- Vcloud::Core::ConfigValidator
- Defined in:
- lib/vcloud/core/config_validator.rb
Overview
self::validate is entry point; this class method is called to instantiate ConfigValidator. For example:
Core::ConfigValidator.validate(key, data, schema)
Recursion in this class
Note that this class will recursively call itself in order to validate deep hash and array structures.
The data
variable is usually either an array or hash and so will pass through the ConfigValidator#validate_array and ConfigValidator#validate_hash methods respectively.
These methods then recursively instantiate this class by calling ConfigValidator::validate again (ConfigValidator#validate_hash calls this indirectly via the ConfigValidator#check_hash_parameter method).
Constant Summary collapse
- VALID_ALPHABETICAL_VALUES_FOR_IP_RANGE =
%w(Any external internal)
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key, data, schema) ⇒ ConfigValidator
constructor
A new instance of ConfigValidator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(key, data, schema) ⇒ ConfigValidator
Returns a new instance of ConfigValidator.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vcloud/core/config_validator.rb', line 34 def initialize(key, data, schema) raise "Nil schema" unless schema raise "Invalid schema" unless schema.key?(:type) @type = schema[:type].to_s.downcase @errors = [] @warnings = [] @data = data @schema = schema @key = key validate end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
26 27 28 |
# File 'lib/vcloud/core/config_validator.rb', line 26 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
26 27 28 |
# File 'lib/vcloud/core/config_validator.rb', line 26 def errors @errors end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
26 27 28 |
# File 'lib/vcloud/core/config_validator.rb', line 26 def key @key end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
26 27 28 |
# File 'lib/vcloud/core/config_validator.rb', line 26 def schema @schema end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
26 27 28 |
# File 'lib/vcloud/core/config_validator.rb', line 26 def type @type end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
26 27 28 |
# File 'lib/vcloud/core/config_validator.rb', line 26 def warnings @warnings end |
Class Method Details
.validate(key, data, schema) ⇒ Object
30 31 32 |
# File 'lib/vcloud/core/config_validator.rb', line 30 def self.validate(key, data, schema) new(key, data, schema) end |
Instance Method Details
#valid? ⇒ Boolean
46 47 48 |
# File 'lib/vcloud/core/config_validator.rb', line 46 def valid? @errors.empty? end |