Module: Icinga2::Validator
- Included in:
- Client
- Defined in:
- lib/icinga2/validator.rb
Overview
namespace for validate options
Instance Method Summary collapse
-
#validate(params, options) ⇒ Object
validate( params, { required: true, var: name, type: String } ).
- #validate_options!(params, options) ⇒ Object
Instance Method Details
#validate(params, options) ⇒ Object
validate( params, { required: true, var: name, type: String } )
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/icinga2/validator.rb', line 35 def validate( params, ) required = .dig(:required) || false var = .dig(:var) type = .dig(:type) params = params.deep_symbolize_keys variable = params.dig(var.to_sym) # puts params # puts options clazz = Object.const_get(type.to_s) if(required == true ) raise ArgumentError.new(format('\'%s\' is requiered and missing!', var)) if(variable.nil?) end raise ArgumentError.new(format('wrong type. \'%s\' must be an %s, given \'%s\'', var, type, variable.class.to_s)) unless( variable.nil? || variable.is_a?(clazz) ) variable end |
#validate_options!(params, options) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/icinga2/validator.rb', line 25 def (params, ) [:optional] ||= [] [:required] ||= [] params = params.deep_symbolize_keys params.assert_required_keys([:required]) params.assert_valid_keys(params, [:required] + [:optional]) end |