Skip to content

Commit

Permalink
addressable: Add Addressable::URI#omit and #omit! (#729)
Browse files Browse the repository at this point in the history
* addressable: Add Addressable::URI#omit

Addressable::URI#omit allows for returning a new instance of
Addressable::URI with the specified components omitted.

https://github.com/sporkmonger/addressable/blob/4229164843616783287ca359bbe38b574f1908a3/lib/addressable/uri.rb#L2285-L2314

* addressable: Add Addressable::URI#omit!
  • Loading branch information
rossta authored Nov 19, 2024
1 parent 5fcf7d4 commit 443b293
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions gems/addressable/2.8/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
# "fragment" => "foo"
# }

uri = Addressable::URI.parse(
"http://example.com/a/b/c"
)
uri = Addressable::URI.parse("http://example.com/a/b/c")
uri.query_values # => nil
uri.query_values = {"one" => "1", "two" => "2"}
uri.query_values # => {"one" => "1", "two" => "2"}
Expand All @@ -62,3 +60,14 @@
uri.query_values # => {"seven"=>"7", "andup"=>"10"}
uri.query_values = nil
uri.query_values # => nil


uri = Addressable::URI.parse("http://example.com/go?a=b&c=d")
uri.omit(:query).to_s # => "http://example.com/go"
uri.omit(:scheme, :path, :query).to_s # => "example.com"

uri = Addressable::URI.parse("http://example.com/go?a=b&c=d")
uri.omit!(:query)
uri.to_s # => "http://example.com"
uri.omit!(:scheme, :path)
uri.to_s # => "example.com"
2 changes: 2 additions & 0 deletions gems/addressable/2.8/addressable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module Addressable
def domain: () -> String
def authority: () -> String
def authority=: (String new_authority) -> String
def omit: (*Symbol components) -> URI
def omit!: (*Symbol components) -> URI
def origin: () -> String
def origin=: (String new_origin) -> String
attr_reader port: Integer
Expand Down

0 comments on commit 443b293

Please sign in to comment.