Sha256: 1412260b2191fad3280844cf5679a7bf900b888c0fc11eb676d7e11f888bd39d
Contents?: true
Size: 1.25 KB
Versions: 29
Compression:
Stored size: 1.25 KB
Contents
module Gitlab module Triage class ParamsValidator def initialize(parameter_definitions, value) @parameter_definitions = parameter_definitions @value = value end def validate! validate_required_parameters(@value) validate_parameter_types(@value) validate_parameter_content(@value) end private def validate_required_parameters(value) @parameter_definitions.each do |param| raise ArgumentError, "#{param[:name]} is a required parameter" unless value[param[:name]] end end def validate_parameter_types(value) @parameter_definitions.each do |param| if value.has_key?(param[:name]) param_types = Array(param[:type]).flatten raise ArgumentError, "#{param[:name]} must be of type #{param[:type]}" unless param_types.any? { |type| value[param[:name]].is_a?(type) } end end end def validate_parameter_content(value) @parameter_definitions.each do |param| if param[:values] raise ArgumentError, "#{param[:name]} must be of one of #{param[:values].join(',')}" unless param[:values].include?(value[param[:name]]) end end end end end end
Version data entries
29 entries across 29 versions & 1 rubygems