Module: Avski::Common::Utils::Validation
- Defined in:
- lib/avski/common/utils.rb
Overview
Utility methods for Validation
Class Method Summary collapse
-
.check_fields(required_fields, params) ⇒ Object
Check if fields used in method params have their values empty or keys are missing.
Class Method Details
.check_fields(required_fields, params) ⇒ Object
Check if fields used in method params have their values empty or keys are missing
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/avski/common/utils.rb', line 64 def self.check_fields(required_fields, params) required_fields, missing, empty, null = required_fields, [], [], [] required_fields.each { |key| missing.push(key) unless params.keys.include?(key) empty.push(key) if params[key.to_sym].eql?('') null.push(key) if params[key.to_sym].nil? } raise UnknownFieldException.new("Missing field(s) -> #{missing.join(', ')}.", 400) if missing.length > 0 raise EmptyFieldException.new("Empty field(s) -> #{empty.join(', ')}.", 400) if empty.length > 0 raise NullFieldException.new("Null field(s) -> #{null.join(', ')}.", 400) if null.length > 0 end |