mirror of
https://github.com/meineerde/rackstash.git
synced 2025-12-19 15:01:12 +00:00
Work around deprecations on Ruby 2.5.0
This commit is contained in:
parent
5962b84f99
commit
dda72c2f84
@ -140,15 +140,28 @@ module Rackstash
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if ip.ipv4?
|
native = ip.native
|
||||||
masked_ip = ip.mask(32 - @ipv4_mask)
|
if native.ipv4?
|
||||||
elsif ip.ipv4_compat? || ip.ipv4_mapped?
|
masked = native.mask(32 - @ipv4_mask)
|
||||||
masked_ip = ip.mask(128 - @ipv4_mask)
|
# Check whether the original IP address was an IPv4 address embedded
|
||||||
elsif ip.ipv6?
|
# into the IPv6 format. If the original IP was either an
|
||||||
masked_ip = ip.mask(128 - @ipv6_mask)
|
# IPv4-compatible IPv6 addresses or an IPv4-mapped IPv6 addresses, we
|
||||||
|
# transform the resulting mapped IP address back into that format.
|
||||||
|
if ip.ipv6?
|
||||||
|
masked = if ip.ipv4_mapped?
|
||||||
|
masked.ipv4_mapped
|
||||||
|
else
|
||||||
|
# This is a bit awkward. Howeverm since Ruby 2.5.0 deprecated
|
||||||
|
# IPAddr#ipv4_compat, we have to do the transformation manually
|
||||||
|
# to avoid the associated warning.
|
||||||
|
IPAddr.new(masked, ::Socket::AF_INET6)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
masked = native.mask(128 - @ipv6_mask)
|
||||||
end
|
end
|
||||||
|
|
||||||
masked_ip.to_s.force_encoding(Encoding::UTF_8)
|
masked.to_s.force_encoding(Encoding::UTF_8)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -479,7 +479,7 @@ describe Rackstash::Fields::AbstractCollection do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'transforms BigDecimal to String' do
|
it 'transforms BigDecimal to String' do
|
||||||
bigdecimal = BigDecimal.new('123.987653')
|
bigdecimal = BigDecimal('123.987653')
|
||||||
|
|
||||||
expect(normalize(bigdecimal)).to eql '123.987653'
|
expect(normalize(bigdecimal)).to eql '123.987653'
|
||||||
expect(normalize(bigdecimal).encoding).to eql Encoding::UTF_8
|
expect(normalize(bigdecimal).encoding).to eql Encoding::UTF_8
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user