ipaddr-ext 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/ipaddr-ext/extensions.rb +10 -0
- data/lib/ipaddr-ext/json.rb +15 -3
- data/lib/ipaddr-ext/version.rb +1 -1
- data/lib/ipaddr-ext.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fb5976cf49eb88720a9e1eb813f40f8ad390130f7095b5c9729368117ca37ad
|
4
|
+
data.tar.gz: 673d199fa8a14c42138accc2d9c39d3fc558f36781f38d311ad627f2618af8a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4619358ca982d7d672f875b3c1dd590283056459fd6e13aa6b505587dfc42f0df4b757597c1ab17dc10cb70b184eebf93f8c98e9d22abcb6dc1c3e6eb562ef63
|
7
|
+
data.tar.gz: d10d7ac3cb147c017f3b31aecb1563b3b6a4cf9482037d93a0e6990258375cebb04b3bb126c35d877d5acbc2902f7bc8ba5b313fd6d18a4330dee01fe8e8857b
|
data/README.md
CHANGED
@@ -58,6 +58,12 @@ ipaddr5.to_host.succ.to_s_with_prefix
|
|
58
58
|
# to_json: export with prefix string
|
59
59
|
IPAddr.new("3ffe:505:2::/64").to_json
|
60
60
|
=> "\"3ffe:505:2::/64\""
|
61
|
+
|
62
|
+
# ==: Fix to compare with address prefix
|
63
|
+
IPAddr.new("192.168.1.0/24") == IPAddr.new("192.168.1.0/24")
|
64
|
+
=> true
|
65
|
+
IPAddr.new("192.168.1.0/24") == IPAddr.new("192.168.1.0/25")
|
66
|
+
=> false # different behavior with pure IPAddr class
|
61
67
|
```
|
62
68
|
|
63
69
|
## Development
|
@@ -36,6 +36,16 @@ module IPAddrExt
|
|
36
36
|
_to_string(mask)
|
37
37
|
end
|
38
38
|
|
39
|
+
# Returns true if two ipaddrs are equal.
|
40
|
+
# Overwrite original == method, fixing to compare address with prefix
|
41
|
+
def ==(other)
|
42
|
+
other = coerce_other(other)
|
43
|
+
rescue
|
44
|
+
false
|
45
|
+
else
|
46
|
+
@family == other.family && @addr == other.to_i && prefix == other.prefix
|
47
|
+
end
|
48
|
+
|
39
49
|
# Returns a address greater than the original address by offset
|
40
50
|
# @param offset [Integer]
|
41
51
|
def +(offset)
|
data/lib/ipaddr-ext/json.rb
CHANGED
@@ -2,13 +2,25 @@
|
|
2
2
|
|
3
3
|
module IPAddrExt
|
4
4
|
module JSON
|
5
|
+
# Fix ActiveSupport::JSON.encode which remove the prefix address when encode with IPAddr/CIDR
|
6
|
+
# https://github.com/rails/rails/issues/46006
|
7
|
+
def self.remove_as_json
|
8
|
+
if IPAddr.method_defined? :as_json
|
9
|
+
IPAddr.remove_method :as_json
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
5
13
|
def to_json
|
14
|
+
format("\"%s\"", as_json)
|
15
|
+
end
|
16
|
+
|
17
|
+
def as_json(options = nil)
|
6
18
|
if ipv4? && prefix == 32
|
7
|
-
|
19
|
+
to_s
|
8
20
|
elsif ipv6? && prefix == 128
|
9
|
-
|
21
|
+
to_s
|
10
22
|
else
|
11
|
-
format("
|
23
|
+
format("%s/%s", to_s, prefix)
|
12
24
|
end
|
13
25
|
end
|
14
26
|
end
|
data/lib/ipaddr-ext/version.rb
CHANGED
data/lib/ipaddr-ext.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ipaddr-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taketo Takashima
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
81
|
+
rubygems_version: 3.5.9
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Extensions for IPAddr Class
|