better_ipaddr 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/better_ipaddr/classes.rb +26 -0
- data/lib/better_ipaddr/constants.rb +1 -0
- data/lib/better_ipaddr/host_methods.rb +66 -0
- data/lib/better_ipaddr/kernel_method.rb +6 -0
- data/lib/better_ipaddr/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7331f1ceb9efec5d87562f785d12963e96239579
|
4
|
+
data.tar.gz: 821dd58b4ef97f9348d82e488ae10db4a93c31db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b35e338ab45746641792dd3a94b507b8b8581cafa4ce0225dbafd804fe01e382415081c8391fad1db585042b442bc4c56c2ddea66023f6cbe2c01673e144b2c2
|
7
|
+
data.tar.gz: 5d29730ae82e1d9e21259d15ea2732e01198cd603a3a9a6db321d813486c0a4e50c0b44a2f2f81f8da0f722f4052ed762f1deeec51811f69c885fdc9b09ee6eb
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "better_ipaddr/constants"
|
2
2
|
require "better_ipaddr/methods"
|
3
|
+
require "better_ipaddr/host_methods"
|
3
4
|
|
4
5
|
class IPAddr
|
5
6
|
class Base < IPAddr
|
@@ -53,6 +54,21 @@ class IPAddr
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
57
|
+
# Create an IPAddr host subclass from the given object, guessing the type of
|
58
|
+
# address given based on its type and content.
|
59
|
+
#
|
60
|
+
# Uses .from internally, so the same concerns apply, though the returned
|
61
|
+
# object is guaranteed to be of a Host class or nil.
|
62
|
+
|
63
|
+
def self.host_from(address)
|
64
|
+
ip = from(address)
|
65
|
+
if ip.ipv4?
|
66
|
+
V4::Host[ip]
|
67
|
+
elsif ip.ipv6?
|
68
|
+
V6::Host[ip]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
56
72
|
# Create an IPAddr from an Integer.
|
57
73
|
#
|
58
74
|
# @param address [Integer]
|
@@ -193,6 +209,8 @@ class IPAddr
|
|
193
209
|
const_set(:PREFIX_LENGTH_TO_NETMASK,
|
194
210
|
PREFIX_LENGTH_TO_NETMASK.fetch(self::FAMILY))
|
195
211
|
const_set(:MAX_INT, 2**self::BIT_LENGTH - 1)
|
212
|
+
const_set(:HOST_NETMASK,
|
213
|
+
self::PREFIX_LENGTH_TO_NETMASK.fetch(self::BIT_LENGTH))
|
196
214
|
end
|
197
215
|
|
198
216
|
def address_family_bit_length
|
@@ -212,12 +230,20 @@ class IPAddr
|
|
212
230
|
specialize_constants Family::IPV4
|
213
231
|
|
214
232
|
REGEX = Regex::IPV4
|
233
|
+
|
234
|
+
class Host < V4
|
235
|
+
include BetterIpaddr::HostMethods
|
236
|
+
end
|
215
237
|
end
|
216
238
|
|
217
239
|
class V6 < Base
|
218
240
|
specialize_constants Family::IPV6
|
219
241
|
|
220
242
|
REGEX = Regex::IPV6
|
243
|
+
|
244
|
+
class Host < V6
|
245
|
+
include BetterIpaddr::HostMethods
|
246
|
+
end
|
221
247
|
end
|
222
248
|
|
223
249
|
class MAC < Base
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module BetterIpaddr
|
2
|
+
module HostMethods
|
3
|
+
def initialize(*)
|
4
|
+
super
|
5
|
+
@mask_addr = netmask.to_i
|
6
|
+
end
|
7
|
+
|
8
|
+
# Returns true if the argument is the same as the receiver, false otherwise.
|
9
|
+
|
10
|
+
def cover?(other)
|
11
|
+
self == other
|
12
|
+
end
|
13
|
+
|
14
|
+
# @overload each
|
15
|
+
# Yield the object. Returns the object.
|
16
|
+
# @yield [IPAddr]
|
17
|
+
# @return [IPAddr]
|
18
|
+
|
19
|
+
# @overload each
|
20
|
+
# Return an enumerator with the behavior described above.
|
21
|
+
# @return [Enumerator]
|
22
|
+
|
23
|
+
def each
|
24
|
+
if block_given?
|
25
|
+
yield self
|
26
|
+
else
|
27
|
+
enum_for(:each)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the object.
|
32
|
+
# @return [IPAddr]
|
33
|
+
|
34
|
+
def first
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns true.
|
39
|
+
|
40
|
+
def host?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the object.
|
45
|
+
# @return [IPAddr]
|
46
|
+
|
47
|
+
def last
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
# Returns the netmask for a host address.
|
52
|
+
def netmask
|
53
|
+
self.class::HOST_NETMASK
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns the number of bits in the address.
|
57
|
+
def prefix_length
|
58
|
+
self.class::BIT_LENGTH
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns 1.
|
62
|
+
def size
|
63
|
+
1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
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
|
+
version: 0.4.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-
|
11
|
+
date: 2016-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/better_ipaddr/classes.rb
|
74
74
|
- lib/better_ipaddr/constants.rb
|
75
75
|
- lib/better_ipaddr/core_extension.rb
|
76
|
+
- lib/better_ipaddr/host_methods.rb
|
76
77
|
- lib/better_ipaddr/kernel_method.rb
|
77
78
|
- lib/better_ipaddr/methods.rb
|
78
79
|
- lib/better_ipaddr/space.rb
|
@@ -97,8 +98,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
98
|
version: '0'
|
98
99
|
requirements: []
|
99
100
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.5.
|
101
|
+
rubygems_version: 2.5.1
|
101
102
|
signing_key:
|
102
103
|
specification_version: 4
|
103
104
|
summary: IPAddr enhancements for network management.
|
104
105
|
test_files: []
|
106
|
+
has_rdoc:
|