Sha256: bd68b2d9ae2abc42579837d40d0cb817ab50280862dddfc7af5d729ebf2776ad

Contents?: true

Size: 881 Bytes

Versions: 1

Compression:

Stored size: 881 Bytes

Contents

# frozen_string_literal: true
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|
          if keys.include?(k) || BitBucket::Validations::VALID_API_KEYS.include?(k)
            filter!(keys, params[k]) if options[:recursive]
          else
            params.delete(k)
          end
        end
      when Array
        params.map! do |el|
          filter!(keys, el) if options[:recursive]
        end
      else
        params
      end
      params
    end
  end # Filter
end # BitBucket

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bitbuckets-0.2.0 lib/bitbucket_rest_api/parameter_filter.rb