Module: Grafana::Validator
- Included in:
- Client
- Defined in:
- lib/grafana/validator.rb
Overview
namespace for validate options
Instance Method Summary collapse
-
#validate(params, options) ⇒ Mixed
validate some parameters.
-
#validate_hash(value, valid_params) ⇒ Mixed
validate an value with an array of values.
Instance Method Details
#validate(params, options) ⇒ Mixed
validate some parameters
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/grafana/validator.rb', line 21 def validate( params, ) required = .dig(:required) || false var = .dig(:var) type = .dig(:type) params = params.deep_symbolize_keys variable = params.dig(var.to_sym) raise ArgumentError.new(format('\'%s\' is requiered and missing!', var)) if(variable.nil? && required == true ) unless( type.nil? ) clazz = Object.const_get(type.to_s) 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) ) end variable end |
#validate_hash(value, valid_params) ⇒ Mixed
validate an value with an array of values
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/grafana/validator.rb', line 44 def validate_hash( value, valid_params ) # puts "validate_hash( #{value}, #{valid_params} )" unless( valid_params.collect { |r| r.downcase }.include?(value.downcase) ) # puts "NOOO : #{value}" return { 'status' => 404, 'message' => format( 'wrong value. \'%s\' must be one of \'%s\'', value, valid_params.join('\', \'')) } end # puts "result: #{result} #{result.class}" # # # downcased = Set.new valid_params.map(&:downcase) # # puts "downcased: #{downcased}" # # unless( downcased.include?( value.downcase ) ) # return { # 'status' => 404, # 'message' => format( 'wrong value. \'%s\' must be one of \'%s\'', value, valid_params.join('\', \'')) # } # end true end |