Module: Gitlab::Config::Entry::Validators::NestedArrayHelpers

Included in:
NestedArrayOfHashesOrArraysValidator, StringOrNestedArrayOfStringsValidator
Defined in:
lib/gitlab/config/entry/validators/nested_array_helpers.rb

Overview

Include this module to validate deeply nested array of values

class MyNestedValidator < ActiveModel::EachValidator

include NestedArrayHelpers

def validate_each(record, attribute, value)
  max_depth = options.fetch(:max_depth, 1)

  unless validate_nested_array(value, max_depth) { |v| v.is_a?(Integer) }
    record.errors.add(attribute, "is invalid")
  end
end

end

Instance Method Summary collapse

Instance Method Details

#validate_nested_array(value, max_depth = 1, &validator_proc) ⇒ Object



22
23
24
25
26
# File 'lib/gitlab/config/entry/validators/nested_array_helpers.rb', line 22

def validate_nested_array(value, max_depth = 1, &validator_proc)
  return false unless value.is_a?(Array)

  validate_nested_array_recursively(value, max_depth, &validator_proc)
end