Module: UltraConfig::Validation

Includes:
Boolean
Included in:
Config
Defined in:
lib/ultra_config/validation.rb

Defined Under Namespace

Classes: TypeValidationError, ValidationError

Instance Method Summary collapse

Instance Method Details

#custom(&block) ⇒ Object

Raises:



43
44
45
# File 'lib/ultra_config/validation.rb', line 43

def custom(&block)
  raise ValidationError unless block.call(@intermediate_value)
end

#match(regexp) ⇒ Object

Raises:



35
36
37
# File 'lib/ultra_config/validation.rb', line 35

def match(regexp)
  raise ValidationError unless regexp.match(@intermediate_value)
end

#one_of(list) ⇒ Object

Raises:



31
32
33
# File 'lib/ultra_config/validation.rb', line 31

def one_of(list)
  raise ValidationError unless list.include?(@intermediate_value)
end

#range(low, high) ⇒ Object

Raises:



39
40
41
# File 'lib/ultra_config/validation.rb', line 39

def range(low, high)
  raise ValidationError unless (@intermediate_value >= low && @intermediate_value <= high)
end

#type_safety(type) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/ultra_config/validation.rb', line 21

def type_safety(type)
  @type_safety_checked = true

  return unless type == :strong
  return if @value.nil?
  return if @value.is_a?(Boolean) && @intermediate_value.is_a?(Boolean)

  raise TypeValidationError if @value.class != @intermediate_value.class
end