Class: Qonfig::Validation::Validators::ProcBased Private

Inherits:
Basic
  • Object
show all
Defined in:
lib/qonfig/validation/validators/proc_based.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.20.0

Instance Attribute Summary collapse

Attributes inherited from Basic

#setting_key_matcher, #strict

Instance Method Summary collapse

Methods inherited from Basic

#validate

Constructor Details

#initialize(setting_key_matcher, strict, validation) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Since:

  • 0.20.0



19
20
21
22
# File 'lib/qonfig/validation/validators/proc_based.rb', line 19

def initialize(setting_key_matcher, strict, validation)
  super(setting_key_matcher, strict)
  @validation = validation
end

Instance Attribute Details

#validationProc (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Proc)

Since:

  • 0.20.0



10
11
12
# File 'lib/qonfig/validation/validators/proc_based.rb', line 10

def validation
  @validation
end

Instance Method Details

#validate_concrete(data_set) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

  • (Boolean)

Raises:

Since:

  • 0.20.0



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/qonfig/validation/validators/proc_based.rb', line 31

def validate_concrete(data_set)
  data_set.settings.__deep_each_setting__ do |setting_key, setting_value|
    next unless setting_key_matcher.match?(setting_key)
    next if !strict && setting_value.nil?

    raise(
      Qonfig::ValidationError,
      "Invalid value of setting <#{setting_key}> (#{setting_value})"
    ) unless data_set.instance_exec(setting_value, &validation)
  end
end

#validate_full(data_set) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

  • (Boolean)

Raises:

Since:

  • 0.20.0



50
51
52
53
54
# File 'lib/qonfig/validation/validators/proc_based.rb', line 50

def validate_full(data_set)
  unless data_set.instance_eval(&validation)
    raise(Qonfig::ValidationError, 'Invalid config object')
  end
end