Sha256: 7525c7602f7fb9cb5754afef4cade350e3864a28051e5f83143a96f2aef55c37

Contents?: true

Size: 473 Bytes

Versions: 7

Compression:

Stored size: 473 Bytes

Contents

module URI
  # Merges the `new_params` with the existing query parameters from the `url`
  def self.replace_params(url, new_params)
    uri = parse url
    params = params_hash(uri).merge new_params
    new_url = "#{uri.scheme}://#{uri.host}#{uri.path}?#{new_params.to_query}##{uri.fragment}"
    parse new_url
  end

  # Extracts a ruby hash from the URI query string
  def self.params_hash(uri)
    Hash[CGI.parse(uri.query).collect { |k, v| [k, v.join('')] }]
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
arctic-vendor-1.0.1 lib/arctic/vendor/uri.rb
arctic-vendor-1.0.0 lib/arctic/vendor/uri.rb
arctic-vendor-0.2.4 lib/arctic/vendor/uri.rb
arctic-vendor-0.2.3 lib/arctic/vendor/uri.rb
arctic-vendor-0.2.2 lib/arctic/vendor/uri.rb
arctic-vendor-0.2.0 lib/arctic/vendor/uri.rb
arctic-vendor-0.1.0 lib/arctic/vendor/uri.rb