Sha256: 1f6246fd7a8959dddab9f48b9a87f43e0d1be14ca30be42ff87aeae8877e5599

Contents?: true

Size: 648 Bytes

Versions: 32

Compression:

Stored size: 648 Bytes

Contents

module ActiveUtils #:nodoc:
  module RequiresParameters #:nodoc:
    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)

          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])
        else
          raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param)
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
active_utils-3.4.1 lib/active_utils/requires_parameters.rb
active_utils-3.4.0 lib/active_utils/requires_parameters.rb
active_utils-3.3.19 lib/active_utils/requires_parameters.rb
active_utils-3.3.18 lib/active_utils/requires_parameters.rb
active_utils-3.3.17 lib/active_utils/requires_parameters.rb
active_utils-3.3.16 lib/active_utils/requires_parameters.rb
active_utils-3.3.15 lib/active_utils/requires_parameters.rb
active_utils-3.3.14 lib/active_utils/requires_parameters.rb
active_utils-3.3.13 lib/active_utils/requires_parameters.rb
active_utils-3.3.12 lib/active_utils/requires_parameters.rb
active_utils-3.3.11 lib/active_utils/requires_parameters.rb
active_utils-3.3.10 lib/active_utils/requires_parameters.rb
active_utils-3.3.9 lib/active_utils/requires_parameters.rb
active_utils-3.3.8 lib/active_utils/requires_parameters.rb
active_utils-3.3.7 lib/active_utils/requires_parameters.rb
active_utils-3.3.6 lib/active_utils/requires_parameters.rb
active_utils-3.3.5 lib/active_utils/requires_parameters.rb
active_utils-3.3.4 lib/active_utils/requires_parameters.rb
active_utils-3.3.3 lib/active_utils/requires_parameters.rb
active_utils-3.3.2 lib/active_utils/requires_parameters.rb