Class: Bolt::Config::Validator
- Inherits:
-
Object
- Object
- Bolt::Config::Validator
- Defined in:
- lib/bolt/config/validator.rb
Instance Attribute Summary collapse
-
#deprecations ⇒ Object
readonly
Returns the value of attribute deprecations.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#check_deprecated(key, definition, location) ⇒ Object
Adds a warning if the given option is deprecated.
-
#initialize ⇒ Validator
constructor
A new instance of Validator.
-
#validate(data, schema, location = nil) ⇒ Object
This is the entry method for validating data against the schema.
Constructor Details
#initialize ⇒ Validator
Returns a new instance of Validator.
13 14 15 16 17 18 |
# File 'lib/bolt/config/validator.rb', line 13 def initialize @errors = [] @deprecations = [] @warnings = [] @path = [] end |
Instance Attribute Details
#deprecations ⇒ Object (readonly)
Returns the value of attribute deprecations.
11 12 13 |
# File 'lib/bolt/config/validator.rb', line 11 def deprecations @deprecations end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
11 12 13 |
# File 'lib/bolt/config/validator.rb', line 11 def warnings @warnings end |
Instance Method Details
#check_deprecated(key, definition, location) ⇒ Object
Adds a warning if the given option is deprecated.
45 46 47 48 49 50 51 52 |
# File 'lib/bolt/config/validator.rb', line 45 def check_deprecated(key, definition, location) if definition.key?(:_deprecation) = "Option '#{path}' " += "at #{location} " if location += "is deprecated. #{definition[:_deprecation]}" @deprecations << { option: key, message: } end end |
#validate(data, schema, location = nil) ⇒ Object
This is the entry method for validating data against the schema. It loops over each key-value pair in the data hash and validates the value against the relevant schema definition.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bolt/config/validator.rb', line 24 def validate(data, schema, location = nil) @location = location validate_keys(data.keys, schema.keys) data.each_pair do |key, value| next unless schema.key?(key) @path.push(key) check_deprecated(key, schema[key], location) validate_value(value, schema[key]) ensure @path.pop end raise_error end |