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
45
46
47
|
# File 'lib/ultra_config/validation.rb', line 45
def custom(&block)
raise ValidationError unless block.call(@intermediate_value)
end
|
#match(regexp) ⇒ Object
37
38
39
|
# File 'lib/ultra_config/validation.rb', line 37
def match(regexp)
raise ValidationError unless regexp.match(@intermediate_value)
end
|
#one_of(list) ⇒ Object
31
32
33
34
35
|
# File 'lib/ultra_config/validation.rb', line 31
def one_of(list)
@intermediate_value = @intermediate_value.to_sym if list.all? { |i| i.is_a?(Symbol) }
raise ValidationError unless list.include?(@intermediate_value)
end
|
#range(low, high) ⇒ Object
41
42
43
|
# File 'lib/ultra_config/validation.rb', line 41
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
|