Sha256: 2c04530e8ea40a298a3f1bb3c811e2a4a21b4255c096b24b019ff0444ba9d9d5

Contents?: true

Size: 974 Bytes

Versions: 20

Compression:

Stored size: 974 Bytes

Contents

# -*- encoding: utf-8 -*-

module Nimbu
  module Request
    # Allows you to specify parameters keys which will be preserved
    # in parameters hash and its subhashes. Any keys from the nested
    # hash that do not match will be removed.
    module ParameterFilter

      # Removes any keys from nested hashes that don't match predefiend keys
      #
      def filter!(keys, params, options={:recursive => true})  # :nodoc:
        case params
        when Hash
          params.keys.each do |k, v|
            unless (keys.include?(k) or Nimbu::Validations::VALID_API_KEYS.include?(k))
              params.delete(k)
            else
              filter!(keys, params[k]) if options[:recursive]
            end
          end
        when Array
          params.map! do |el|
            filter!(keys, el) if options[:recursive]
          end
        else
          params
        end
        return params
      end

    end # ParameterFilter
  end # Request
end # Nimbu

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nimbu-api-0.5.0 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.4.4 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.4.3 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.4.2 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.4.1 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.4.0 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.3.0 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.2.1 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.2 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.2.beta.3 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.2.beta.2 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.2.beta.1 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.2.beta lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.1.5 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.1.4 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.1.3 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.1.1 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.1 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.0.2 lib/nimbu-api/request/parameter_filter.rb
nimbu-api-0.0.1 lib/nimbu-api/request/parameter_filter.rb