Module: OptionsHelper

Included in:
Trackerific::Configuration, Trackerific::Service
Defined in:
lib/helpers/options_helper.rb

Overview

Helper for validating required options

Instance Method Summary (collapse)

Instance Method Details

- (Object) validate_options(options, required)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Validates a list of options against a list of required options

Parameters:

  • options (Array)

    list of options to validate

  • required (Array)

    list of required options

Returns:

  • true

Raises:

  • (ArgumentError)

    if the options do not pass validation



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/helpers/options_helper.rb', line 9

def validate_options(options, required)
  # make sure all the required options exist
  required.each do |k|
    raise ArgumentError.new("Missing required parameter: #{k}") unless options.has_key?(k)
  end
  # make sure no invalid options exist
  options.each do |k, v|
    raise ArgumentError.new("Invalid parameter: #{k}") unless required.include?(k)
  end
  true
end