lib/codecode/common/utils.rb
# Check if fields used in method params have their values
# empty or keys are missing
# @param [Array[Symbol]] required_fields array of symbols
# @param [Object] params
Check if fields used in method params have their values
empty or keys are missing
Check if fields used in method params have their values empty or keys are missing
def 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
def 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
Check if fields used in method params have their values
empty or keys are missing
Check if fields used in method params have their values empty or keys are missing
required_fields
params
]
required_fields array of symbols
required_fields array of symbols
None