module Sensu::Settings::Rules
Public Instance Methods
Check if either of the values are set (not nil).
@param values [Array<Object>] to check if not nil. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 129 def either_are_set?(*values) values.any? do |value| !value.nil? end end
Check that value items are all strings and not empty.
@param value [Array] with items to check. @param regex [Regexp] to validate string items with. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 118 def items_must_be_strings(value, regex=nil) value.all? do |item| item.is_a?(String) && !item.empty? && (regex.nil? || item =~ regex) end end
Check that a value is a hash.
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 8 def must_be_a_hash(value) value.is_a?(Hash) end
Check that a value is a hash, if set (not nil).
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 17 def must_be_a_hash_if_set(value) value.nil? ? true : must_be_a_hash(value) end
Check that a value is numeric.
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 76 def must_be_a_numeric(value) value.is_a?(Numeric) end
Check that a value is numeric, if set (not nil).
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 84 def must_be_a_numeric_if_set(value) value.nil? ? true : must_be_a_numeric(value) end
Check that a value is a string.
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 42 def must_be_a_string(value) value.is_a?(String) end
Check that a value is a string, if set (not nil).
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 51 def must_be_a_string_if_set(value) value.nil? ? true : must_be_a_string(value) end
Check that a value is an array.
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 25 def must_be_an_array(value) value.is_a?(Array) end
Check that a value is an array, if set (not nil).
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 34 def must_be_an_array_if_set(value) value.nil? ? true : must_be_an_array(value) end
Check that a value is an integer.
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 59 def must_be_an_integer(value) value.is_a?(Integer) end
Check that a value is an integer, if set (not nil).
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 68 def must_be_an_integer_if_set(value) value.nil? ? true : must_be_an_integer(value) end
Check if a value is boolean.
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 101 def must_be_boolean(value) !!value == value end
Check if a value is boolean, if set (no nil).
@param value [Object] to check. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 109 def must_be_boolean_if_set(value) value.nil? ? true : must_be_boolean(value) end
Check if values are allowed.
@param allowed [Array<Object>] allowed values. @param values [Array<Object>] to check if allowed. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 150 def must_be_either(allowed, *values) values.flatten.all? do |value| allowed.include?(value) end end
Check if values are allowed, if set (not nil).
@param allowed [Array<Object>] allowed values. @param values [Array<Object>] to check if allowed. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 161 def must_be_either_if_set(allowed, *values) values[0].nil? ? true : must_be_either(allowed, values) end
Check if values are valid times (can be parsed).
@param values [Array<Object>] to check if valid time. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 139 def must_be_time(*values) values.all? do |value| Time.parse(value) rescue false end end
Check that a value matches a regular expression.
@param regex [Regexp] pattern to compare with value. @param value [Object] to check if matches pattern. @return [TrueClass, FalseClass]
# File lib/sensu/settings/rules.rb, line 93 def must_match_regex(regex, value) (value =~ regex) == 0 end