Class: Bolt::Config::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/bolt/config/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValidator

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

#deprecationsObject (readonly)

Returns the value of attribute deprecations.



11
12
13
# File 'lib/bolt/config/validator.rb', line 11

def deprecations
  @deprecations
end

#warningsObject (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)
    message  = "Option '#{path}' "
    message += "at #{location} " if location
    message += "is deprecated. #{definition[:_deprecation]}"
    @deprecations << { option: key, message: 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