ipaddr-ext 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84e45c02d4f47c83919da49e0ed33015bec5b70b0f520925ae08e5a7fb2005c3
4
- data.tar.gz: 3c146451e5fc613b3aacf1fd5db662c253b2653b12c32a40c9f91fc18b11f67f
3
+ metadata.gz: cf80589f0fb436a83b743951bda416d1797bcfed488cad15b26f40378f95df7b
4
+ data.tar.gz: 6159ab041b42951c635bafc9b7feab379071d5044f9a03133ccd533a2b166e55
5
5
  SHA512:
6
- metadata.gz: 9860c9fa616cd56c56094f563410aae1f2ea4a956c63c7b520fa13503b8245af5934075b817df5c2f18d8a6db79182d24abfba4f1b011778b1e120754ed8b371
7
- data.tar.gz: a80046f2c50c372008890e3ca8095b60d1189ee00182bb3a95784167a58d1c7456d1e26b41baee6b0de58dd97efb76b9b6584d4b664e085f672c52d70a4e9fb0
6
+ metadata.gz: 6e8bcd61f275230ae3ec8937e11d4ef511e188b3487956c3058d50a30552c26afd5a84a4b6f08265b05c1a43d98aebeb8dcc0f70b54dc4cf8f5b6ad843c058db
7
+ data.tar.gz: ee6b3b25223c78ac7823c13f7fa56c34a443f5d83170a6c0b5a2d52a1f872a72e9277681f80a6f6fcc3f5be7d873ebc5b986fcde427a22443c981ab713ba1ba9
@@ -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
- format("\"%s\"", to_s)
19
+ to_s
8
20
  elsif ipv6? && prefix == 128
9
- format("\"%s\"", to_s)
21
+ to_s
10
22
  else
11
- format("\"%s/%s\"", to_s, prefix)
23
+ format("%s/%s", to_s, prefix)
12
24
  end
13
25
  end
14
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IPAddrExt
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/ipaddr-ext.rb CHANGED
@@ -6,4 +6,6 @@ require "ipaddr-ext/extensions"
6
6
  require "ipaddr-ext/json"
7
7
 
8
8
  IPAddr.send(:include, IPAddrExt::Extensions)
9
+
10
+ IPAddrExt::JSON.remove_as_json
9
11
  IPAddr.send(:include, IPAddrExt::JSON)
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.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taketo Takashima
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-15 00:00:00.000000000 Z
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake