Sha256: 557164dc8f13adafc2cbda73c31b437e8b241f7e1d971c97cd88f363383c1388

Contents?: true

Size: 892 Bytes

Versions: 16

Compression:

Stored size: 892 Bytes

Contents

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

module BitBucket
  # 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 BitBucket::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 # Filter
end # BitBucket

Version data entries

16 entries across 16 versions & 4 rubygems

Version Path
zz_bitbucket_rest_api-0.1.11 lib/bitbucket_rest_api/parameter_filter.rb
zz_bitbucket_rest_api-0.1.10 lib/bitbucket_rest_api/parameter_filter.rb
zz_bitbucket_rest_api-0.1.9 lib/bitbucket_rest_api/parameter_filter.rb
zz_bitbucket_rest_api-0.1.8 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api2-0.9.5 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api2-0.9.1 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api2-0.2.2 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api2-0.2.1 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api2-0.2.0 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api-0.1.7 lib/bitbucket_rest_api/parameter_filter.rb
reenhanced_bitbucket_api-0.1.6 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api-0.1.5 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api-0.1.4 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api-0.1.2 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api-0.1.1 lib/bitbucket_rest_api/parameter_filter.rb
bitbucket_rest_api-0.1.0 lib/bitbucket_rest_api/parameter_filter.rb