Sha256: 8e56f26b0cbf4bd8093c210894cbb1823002165cec8884c697ed35b825913d2b

Contents?: true

Size: 904 Bytes

Versions: 5

Compression:

Stored size: 904 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, ParamsHash
        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

5 entries across 5 versions & 2 rubygems

Version Path
codenamev_bitbucket_api-0.4.1 lib/bitbucket_rest_api/parameter_filter.rb
codenamev_bitbucket_api-0.4.0 lib/bitbucket_rest_api/parameter_filter.rb
reenhanced_bitbucket_api-0.3.2 lib/bitbucket_rest_api/parameter_filter.rb
reenhanced_bitbucket_api-0.3.1 lib/bitbucket_rest_api/parameter_filter.rb
reenhanced_bitbucket_api-0.3.0 lib/bitbucket_rest_api/parameter_filter.rb