Module: IPAddrExt::JSON
- Defined in:
- lib/ipaddr-ext/json.rb
Class Method Summary collapse
-
.remove_as_json ⇒ Object
Fix ActiveSupport::JSON.encode which remove the prefix address when encode with IPAddr/CIDR github.com/rails/rails/issues/46006.
Instance Method Summary collapse
Class Method Details
.remove_as_json ⇒ Object
Fix ActiveSupport::JSON.encode which remove the prefix address when encode with IPAddr/CIDR github.com/rails/rails/issues/46006
7 8 9 10 11 |
# File 'lib/ipaddr-ext/json.rb', line 7 def self.remove_as_json if IPAddr.method_defined? :as_json IPAddr.remove_method :as_json end end |
Instance Method Details
#as_json(options = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/ipaddr-ext/json.rb', line 17 def as_json( = nil) if ipv4? && prefix == 32 to_s elsif ipv6? && prefix == 128 to_s else format("%s/%s", to_s, prefix) end end |
#to_json ⇒ Object
13 14 15 |
# File 'lib/ipaddr-ext/json.rb', line 13 def to_json format("\"%s\"", as_json) end |