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
46
47
48
|
# File 'lib/ultra_config/validation.rb', line 46
def custom(&block)
raise ValidationError unless block.call(@intermediate_value)
end
|
#match(regexp) ⇒ Object
38
39
40
|
# File 'lib/ultra_config/validation.rb', line 38
def match(regexp)
raise ValidationError unless regexp.match(@intermediate_value)
end
|
#one_of(list) ⇒ Object
34
35
36
|
# File 'lib/ultra_config/validation.rb', line 34
def one_of(list)
raise ValidationError unless list.include?(@intermediate_value)
end
|
#range(low, high) ⇒ Object
42
43
44
|
# File 'lib/ultra_config/validation.rb', line 42
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
30
31
32
|
# 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)
@intermediate_value = @intermediate_value.to_sym if @intermediate_value.is_a?(String) && @value.is_a?(Symbol)
raise TypeValidationError if @value.class != @intermediate_value.class
end
|