better_ipaddr 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7331f1ceb9efec5d87562f785d12963e96239579
4
- data.tar.gz: 821dd58b4ef97f9348d82e488ae10db4a93c31db
3
+ metadata.gz: 871dfdaf9d8e064ae09988a53d3e991544d414a9
4
+ data.tar.gz: 3d3229104847532b1713497982473e6f08520ee1
5
5
  SHA512:
6
- metadata.gz: b35e338ab45746641792dd3a94b507b8b8581cafa4ce0225dbafd804fe01e382415081c8391fad1db585042b442bc4c56c2ddea66023f6cbe2c01673e144b2c2
7
- data.tar.gz: 5d29730ae82e1d9e21259d15ea2732e01198cd603a3a9a6db321d813486c0a4e50c0b44a2f2f81f8da0f722f4052ed762f1deeec51811f69c885fdc9b09ee6eb
6
+ metadata.gz: d24bedd14d52e7f729af783387d2fe956b9ad4da55bbbfc624ec041046da05854dfcb573b855d131bc727aaa5f74cf879ff3dee01b592b635403c7ce60c5c4a3
7
+ data.tar.gz: 90bcb07ddb3ee7899fa8d8c53d193806004c016e4bf9cc21a1ed3160155edc944f420be46284e4a441cfbc361477a3fe9c447fa751b1ecd24dbcc5aab293b7f9
@@ -224,6 +224,10 @@ class IPAddr
224
224
  def prefix_length
225
225
  self.class::NETMASK_TO_PREFIX_LENGTH[mask_addr]
226
226
  end
227
+
228
+ def to_s(cidr: false, full: false)
229
+ better_to_s(cidr: cidr, full: full)
230
+ end
227
231
  end
228
232
 
229
233
  class V4 < Base
@@ -45,6 +45,13 @@ module BetterIpaddr
45
45
  module InstanceMethods
46
46
  include Constants
47
47
 
48
+ def self.included(base)
49
+ return unless base <= IPAddr
50
+ base.class_eval do
51
+ define_method :stdlib_to_s, IPAddr.instance_method(:to_s)
52
+ end
53
+ end
54
+
48
55
  # Return the magic number representing the address family.
49
56
  # @return [Integer]
50
57
  attr_reader :family
@@ -149,17 +156,28 @@ module BetterIpaddr
149
156
  #
150
157
  # @return [String]
151
158
 
152
- def base
153
- _to_string(@addr)
159
+ def base(full: false)
160
+ if full
161
+ to_string
162
+ else
163
+ stdlib_to_s
164
+ end
165
+ end
166
+
167
+ def better_to_s(cidr: false, full: false)
168
+ if cidr
169
+ "#{base(full: full)}/#{prefix_length}"
170
+ else
171
+ base(full: full)
172
+ end
154
173
  end
155
174
 
156
175
  # Return a string containing the CIDR representation of the address.
157
176
  #
158
177
  # @return [String]
159
178
 
160
- def cidr
161
- return _to_string(@addr) unless ipv4? || ipv6?
162
- "#{_to_string(@addr)}/#{prefixlen}"
179
+ def cidr(cidr: nil, full: false)
180
+ better_to_s(cidr: true, full: full)
163
181
  end
164
182
 
165
183
  # Test whether or not this address completely encloses the other address.
@@ -1,3 +1,3 @@
1
1
  module BetterIpaddr
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_ipaddr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Miller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-06 00:00:00.000000000 Z
11
+ date: 2016-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,4 +103,3 @@ signing_key:
103
103
  specification_version: 4
104
104
  summary: IPAddr enhancements for network management.
105
105
  test_files: []
106
- has_rdoc: