Sha256: 98b41fa6e21b60e2bedb1b4f2eb30d432d179990382404ddfbd283c9e4274f06

Contents?: true

Size: 895 Bytes

Versions: 9

Compression:

Stored size: 895 Bytes

Contents

# Helper for validating required options
module OptionsHelper
  # Validates a list of options against a list of required options
  # @param [Array] options list of options to validate
  # @param [Array] required list of required options
  # @param [Array] valid list of additional valid options
  # @return true
  # @raise [ArgumentError] if the options do not pass validation
  # @api private
  def validate_options(options, required = [], valid = [])
    options = {} if options.nil?
    required = {} if required.nil?
    # 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) || valid.include?(k)
    end
    true
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
trackerific-0.6.2 lib/helpers/options_helper.rb
trackerific-0.6.1 lib/helpers/options_helper.rb
trackerific-0.6.0 lib/helpers/options_helper.rb
trackerific-0.5.5 lib/helpers/options_helper.rb
trackerific-0.5.4 lib/helpers/options_helper.rb
trackerific-0.5.3 lib/helpers/options_helper.rb
trackerific-0.5.2 lib/helpers/options_helper.rb
trackerific-0.5.1 lib/helpers/options_helper.rb
trackerific-0.5.0 lib/helpers/options_helper.rb