Revision 79699411
Added by Dominic Cleal almost 10 years ago
lib/proxy/util.rb | ||
---|---|---|
# convert setting to boolean (with a default value)
|
||
def to_bool(value, default = false)
|
||
return default if value.nil?
|
||
return value if value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
||
!!(value =~ /^(true|t|yes|y|1)$/i)
|
||
end
|
||
|
test/util_test.rb | ||
---|---|---|
def test_to_bool_default_true
|
||
assert UtilClass.to_bool(nil, true)
|
||
end
|
||
|
||
def test_to_bool_true_bool
|
||
assert UtilClass.to_bool true
|
||
end
|
||
|
||
def test_to_bool_false_bool
|
||
assert UtilClass.to_bool(false) == false
|
||
end
|
||
|
||
end
|
Also available in: Unified diff
fixes #5677 - handle booleans from settings.yml as bools