Class: Gitlab::Config::Entry::Validators::VariablesValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Includes:
LegacyValidationHelpers
Defined in:
lib/gitlab/config/entry/validators.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


310
311
312
313
314
315
316
317
318
# File 'lib/gitlab/config/entry/validators.rb', line 310

def validate_each(record, attribute, value)
  if options[:array_values]
    validate_key_array_values(record, attribute, value)
  elsif options[:allowed_value_data]
    validate_key_hash_values(record, attribute, value, options[:allowed_value_data])
  else
    validate_key_values(record, attribute, value)
  end
end

#validate_key_array_values(record, attribute, value) ⇒ Object


326
327
328
329
330
# File 'lib/gitlab/config/entry/validators.rb', line 326

def validate_key_array_values(record, attribute, value)
  unless validate_array_value_variables(value)
    record.errors.add(attribute, 'should be a hash of key value pairs, value can be an array')
  end
end

#validate_key_hash_values(record, attribute, value, allowed_value_data) ⇒ Object


332
333
334
335
336
# File 'lib/gitlab/config/entry/validators.rb', line 332

def validate_key_hash_values(record, attribute, value, allowed_value_data)
  unless validate_string_or_hash_value_variables(value, allowed_value_data)
    record.errors.add(attribute, 'should be a hash of key value pairs, value can be a hash')
  end
end

#validate_key_values(record, attribute, value) ⇒ Object


320
321
322
323
324
# File 'lib/gitlab/config/entry/validators.rb', line 320

def validate_key_values(record, attribute, value)
  unless validate_variables(value)
    record.errors.add(attribute, 'should be a hash of key value pairs')
  end
end