Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this commit there was no way to retrieve the unmasked address
for an
IPAddr
. For example, given theIPAddr
below there is nomethod or instance variable that would return
"1.2.3.4"
.This poses a problem for Rails in supporting the PostgreSQL inet type.
Rails uses
IPAddr
for both the cidr and inet types, but at the momentcannot fully support the inet type, which "accepts values with nonzero
bits to the right of the netmask". This came up originally in
rails/rails#14857, and more recently in
rails/rails#40138. The change in this commit
would allow us to support the inet type without moving to another
library.
This commit holds onto the address before the mask is applied, in a new
instance variable
@unmasked_addr
. It then exposes this viato_unmasked_string
.This was originally implemented back in
#599, but it got stale and was
eventually closed. There are also a few differences with that PR:
mask!
, which meantthat the new method was broken in the case of an
IPAddr
with nomask.
to_s
-like value, whereasthis one returns a
to_string
-like value. This seems to fit betterwith the method name. And if folks need to get the
to_s
value theycan always wrap the return value in another
IPAddr
and callto_s
on that.
signature of
to_s