Sha256: 65a6212dd7278274aa150994235bd630f17f17f61e579063334f654c9849a2fb

Contents?: true

Size: 895 Bytes

Versions: 23

Compression:

Stored size: 895 Bytes

Contents

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

module Github
  # 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 Github::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 # Github

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
github_api-0.17.0 lib/github_api/parameter_filter.rb
github_api-0.16.0 lib/github_api/parameter_filter.rb
github_api-0.15.0 lib/github_api/parameter_filter.rb
github_api-0.14.5 lib/github_api/parameter_filter.rb
github_api-0.14.4 lib/github_api/parameter_filter.rb
github_api-0.14.3 lib/github_api/parameter_filter.rb
github_api-0.14.2 lib/github_api/parameter_filter.rb
github_api-0.14.1 lib/github_api/parameter_filter.rb
github_api-0.14.0 lib/github_api/parameter_filter.rb
github_api-0.13.1 lib/github_api/parameter_filter.rb
github_api-0.13.0 lib/github_api/parameter_filter.rb
github_api-0.12.4 lib/github_api/parameter_filter.rb
github_api-0.12.3 lib/github_api/parameter_filter.rb
github_api-0.12.2 lib/github_api/parameter_filter.rb
github_api-0.12.1 lib/github_api/parameter_filter.rb
github_api-0.12.0 lib/github_api/parameter_filter.rb
github_api-0.11.3 lib/github_api/parameter_filter.rb
github_api-0.11.2 lib/github_api/parameter_filter.rb
github_api-0.11.1 lib/github_api/parameter_filter.rb
github_api-0.11.0 lib/github_api/parameter_filter.rb