Sha256: f6b8f0cbcbf8941043bca1eee24019c2a4472ee4fd500506c4ed597fe9ce9078

Contents?: true

Size: 644 Bytes

Versions: 5

Compression:

Stored size: 644 Bytes

Contents

module ActiveMerchant #:nodoc:
  module RequiresParameters #:nodoc:
    def requires!(hash, *params)
      keys = hash.keys
      params.each do |param| 
        if param.is_a?(Array)
          raise ArgumentError.new("Missing required parameter: #{param}") unless keys.include?(param.first) 

          valid_options = param[1..-1]
          raise ArgumentError.new("Parameter :#{param.first} must be one of #{valid_options.inspect}") unless valid_options.include?(hash[param.first])
        else
          raise ArgumentError.new("Missing required parameter: #{param}") unless keys.include?(param) 
        end
      end
    end    
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activemerchant-1.1.0 lib/active_merchant/lib/requires_parameters.rb
activemerchant-1.0.2 lib/active_merchant/lib/requires_parameters.rb
activemerchant-1.0.1 lib/active_merchant/lib/requires_parameters.rb
activemerchant-1.0.0 lib/active_merchant/lib/requires_parameters.rb
activemerchant-1.0.3 lib/active_merchant/lib/requires_parameters.rb