lib/nfg-client/utils.rb
# Raises an exception if the required params are not part of the given hash
#
# Arguments:
#   hash: (Hash)
#   *params: (Array or Symbol)
Raises an exception if the required params are not part of the given hash
Arguments:
hash: (Hash)
params: (Array or Symbol)
Raises an exception if the required params are not part of the given hash Arguments : hash : ( Hash ) params : ( Array or Symbol )
def requires!(hash, *params)
      params.each do |param|
        if param.is_a?(Array)
          raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash.has_key?(param.first) || hash.has_key?(param.first.to_s)
          valid_options = param[1..-1]
          raise ArgumentError.new("Parameter: #{param.first} must be one of #{valid_options.to_sentence(:words_connector => 'or')}") unless valid_options.include?(hash[param.first]) || valid_options.include?(hash[param.first.to_s])
        else
          raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param) || hash.has_key?(param.to_s)
        end
      end
    end
def requires! ( hash , * params ) params . each do | param | if param . is_a? ( Array ) raise ArgumentError . new ( "Missing required parameter: #{param.first}" ) unless hash . has_key? ( param . first ) || hash . has_key? ( param . first . to_s ) valid_options = param [ 1 .. - 1 ] raise ArgumentError . new ( "Parameter: #{param.first} must be one of #{valid_options.to_sentence(:words_connector => 'or')}" ) unless valid_options . include? ( hash [ param . first ] ) || valid_options . include? ( hash [ param . first . to_s ] ) else raise ArgumentError . new ( "Missing required parameter: #{param}" ) unless hash . has_key? ( param ) || hash . has_key? ( param . to_s ) end end end
Raises an exception if the required params are not part of the given hash
Arguments:
hash: (Hash)
params: (Array or Symbol)
Raises an exception if the required params are not part of the given hash Arguments : hash : ( Hash ) params : ( Array or Symbol )
hash
<not_specific>
params
<not_specific>