better_ipaddr 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +38 -0
- data/better_ipaddr.gemspec +3 -4
- data/lib/better_ipaddr/classes.rb +85 -1
- data/lib/better_ipaddr/methods.rb +6 -0
- data/lib/better_ipaddr/version.rb +1 -1
- metadata +20 -29
- data/.travis.yml +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d0d8d41449838fe7c125436fb675ae3facbcae5552afbdefc57c0a595f1f980
|
4
|
+
data.tar.gz: dc8c7339f8a3787e336882cb812fcb86b3cc62b3d8d492eecd95de87c2f7134d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f13615231d765762a13b41abc77ba161c6ea7c0552fd461477e907d7715c1ac7f7e678045974bf2fd90aec64d0001e99f73f499c9c2abf878b3158494f391689
|
7
|
+
data.tar.gz: 93fe51274de41a9cdcb7cd5e3ecff333e66000294117ef14f0c9fa04bfbc6a511fc97e8d136587e8d1b681889445e93e7db0327dd72fe1280b04374dd6153176
|
@@ -0,0 +1,38 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "master" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "master" ]
|
8
|
+
|
9
|
+
permissions:
|
10
|
+
contents: read
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
strategy:
|
16
|
+
matrix:
|
17
|
+
ruby-version:
|
18
|
+
- '2.3'
|
19
|
+
- '2.4'
|
20
|
+
- '2.5'
|
21
|
+
- '2.6'
|
22
|
+
- '2.7'
|
23
|
+
- '3.0'
|
24
|
+
- '3.1'
|
25
|
+
- jruby-9.1.17.0
|
26
|
+
- jruby-9.2.21.0
|
27
|
+
- jruby-9.3.6.0
|
28
|
+
|
29
|
+
steps:
|
30
|
+
- uses: actions/checkout@v3
|
31
|
+
- name: Set up Ruby
|
32
|
+
# https://github.com/ruby/setup-ruby#versioning
|
33
|
+
uses: ruby/setup-ruby@v1
|
34
|
+
with:
|
35
|
+
ruby-version: ${{ matrix.ruby-version }}
|
36
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
37
|
+
- name: Run tests
|
38
|
+
run: bundle exec rake
|
data/better_ipaddr.gemspec
CHANGED
@@ -20,10 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_development_dependency "
|
24
|
-
spec.add_development_dependency "
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "ipaddr", ">= 1.2.4"
|
24
|
+
spec.add_development_dependency "minitest", "~> 5.0", "< 5.11"
|
25
|
+
spec.add_development_dependency "rake"
|
27
26
|
spec.add_development_dependency "rubocop", "~> 0.54" if RUBY_VERSION > '2.1'
|
28
27
|
spec.add_development_dependency "test-unit"
|
29
28
|
end
|
@@ -33,6 +33,8 @@ class IPAddr
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
# rubocop: disable CyclomaticComplexity
|
37
|
+
|
36
38
|
# Create an IPAddr from the given object, guessing the type of address given
|
37
39
|
# based on its type and content.
|
38
40
|
#
|
@@ -50,6 +52,10 @@ class IPAddr
|
|
50
52
|
# @param classful [Boolean] see Base.from_string
|
51
53
|
# @return [IPAddr, Nil]
|
52
54
|
def self.from(address, exception: false, classful: false)
|
55
|
+
if class_converter?(address)
|
56
|
+
return class_convert(address, classful: classful, exception: exception)
|
57
|
+
end
|
58
|
+
|
53
59
|
case address
|
54
60
|
when IPAddr
|
55
61
|
specialize address
|
@@ -59,7 +65,62 @@ class IPAddr
|
|
59
65
|
V6[address]
|
60
66
|
end || (
|
61
67
|
if exception
|
62
|
-
raise TypeError, "can't convert #{address.inspect} to #{self}"
|
68
|
+
(raise TypeError, "can't convert #{address.inspect} to #{self}")
|
69
|
+
end
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
# rubocop: enable CyclomaticComplexity
|
74
|
+
|
75
|
+
# A Hash of classes and class names which can be converted to IPAddr::Base
|
76
|
+
# subclasses, but which are not necessarily loaded at the same time as this
|
77
|
+
# file.
|
78
|
+
#
|
79
|
+
# Conversion callables for custom classes can be registered here, e.g., with
|
80
|
+
# custom class Foo:
|
81
|
+
#
|
82
|
+
# IPAddr::Base.class_converters[Foo] = proc { |foo, _| foo.to_ipaddr }
|
83
|
+
#
|
84
|
+
# The arguments passed to the callable will be the same as the parameters of
|
85
|
+
# Kernel#IPAddr.
|
86
|
+
#
|
87
|
+
# @return [Hash{String, Class => Proc, Method}]
|
88
|
+
def self.class_converters
|
89
|
+
@class_converters ||= {
|
90
|
+
'Resolv::IPv4' => V4.method(:from_string_representable),
|
91
|
+
'Resolv::IPv6' => V6.method(:from_string_representable)
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
# Return the class_converter for the given object, if one exists.
|
96
|
+
#
|
97
|
+
# Checks by both class identity and class name so that every class with a
|
98
|
+
# converter doesn't need to be loaded for this file to load.
|
99
|
+
#
|
100
|
+
# @return [Proc, Method, Nil]
|
101
|
+
def self.class_converter(address)
|
102
|
+
class_converters[address.class] ||= class_converters[address.class.name]
|
103
|
+
class_converters[address.class]
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.class_converter?(address)
|
107
|
+
class_converters.key?(address.class) ||
|
108
|
+
class_converters.key?(address.class.name)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Convert the given object using its class_converter, if one exists.
|
112
|
+
#
|
113
|
+
# @return [IPAddr, Nil]
|
114
|
+
def self.class_convert(address, mask = nil, classful: nil, exception: false)
|
115
|
+
converter = class_converter(address)
|
116
|
+
converter && converter.call(
|
117
|
+
address,
|
118
|
+
mask,
|
119
|
+
classful: classful,
|
120
|
+
exception: exception
|
121
|
+
) || (
|
122
|
+
if exception
|
123
|
+
(raise TypeError, "can't convert #{address.inspect} to #{self}")
|
63
124
|
end
|
64
125
|
)
|
65
126
|
end
|
@@ -132,6 +193,29 @@ class IPAddr
|
|
132
193
|
end
|
133
194
|
end
|
134
195
|
|
196
|
+
# Create an IPAddr from an object that can be converted to a String via
|
197
|
+
# #to_s.
|
198
|
+
#
|
199
|
+
#
|
200
|
+
# @param address [#to_s]
|
201
|
+
# @param mask [Integer, String] a netmask or prefix length
|
202
|
+
# @param family [Integer, Nil]
|
203
|
+
# @param classful [Boolean] controls the conversion of IPv4 addresses
|
204
|
+
# without a prefix length in CIDR notation. When false, these are assumed
|
205
|
+
# to be host networks (/32). When true, these are assumed to be classful
|
206
|
+
# (rfc791) networks, with an implicit prefix length. Has no effect on IPv6
|
207
|
+
# addresses.
|
208
|
+
# @return [IPAddr]
|
209
|
+
def self.from_string_representable(
|
210
|
+
address,
|
211
|
+
mask = nil,
|
212
|
+
family: self::FAMILY,
|
213
|
+
classful: false,
|
214
|
+
exception: false
|
215
|
+
)
|
216
|
+
from_string(address.to_s, mask, family: family, classful: classful)
|
217
|
+
end
|
218
|
+
|
135
219
|
# Convert an object to a prefix length.
|
136
220
|
#
|
137
221
|
# @param mask [Integer, String]
|
@@ -172,6 +172,12 @@ module BetterIpaddr
|
|
172
172
|
# The first host address in the network.
|
173
173
|
# @return [IPAddr]
|
174
174
|
|
175
|
+
def hash
|
176
|
+
# see https://github.com/jruby/jruby/issues/4460
|
177
|
+
# remove this override when specs still pass without it
|
178
|
+
[self.class, @addr, @mask_addr, @family].hash
|
179
|
+
end
|
180
|
+
|
175
181
|
def first
|
176
182
|
self[0]
|
177
183
|
end
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_ipaddr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Miller
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: ipaddr
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - ">="
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.2.
|
19
|
+
version: 1.2.4
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.2.
|
26
|
+
version: 1.2.4
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: minitest
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,6 +31,9 @@ dependencies:
|
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
33
|
version: '5.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '5.11'
|
48
37
|
type: :development
|
49
38
|
prerelease: false
|
50
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -52,20 +41,23 @@ dependencies:
|
|
52
41
|
- - "~>"
|
53
42
|
- !ruby/object:Gem::Version
|
54
43
|
version: '5.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '5.11'
|
55
47
|
- !ruby/object:Gem::Dependency
|
56
48
|
name: rake
|
57
49
|
requirement: !ruby/object:Gem::Requirement
|
58
50
|
requirements:
|
59
|
-
- - "
|
51
|
+
- - ">="
|
60
52
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
53
|
+
version: '0'
|
62
54
|
type: :development
|
63
55
|
prerelease: false
|
64
56
|
version_requirements: !ruby/object:Gem::Requirement
|
65
57
|
requirements:
|
66
|
-
- - "
|
58
|
+
- - ">="
|
67
59
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
60
|
+
version: '0'
|
69
61
|
- !ruby/object:Gem::Dependency
|
70
62
|
name: rubocop
|
71
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,16 +86,16 @@ dependencies:
|
|
94
86
|
- - ">="
|
95
87
|
- !ruby/object:Gem::Version
|
96
88
|
version: '0'
|
97
|
-
description:
|
89
|
+
description:
|
98
90
|
email:
|
99
91
|
- bmiller@rackspace.com
|
100
92
|
executables: []
|
101
93
|
extensions: []
|
102
94
|
extra_rdoc_files: []
|
103
95
|
files:
|
96
|
+
- ".github/workflows/ruby.yml"
|
104
97
|
- ".gitignore"
|
105
98
|
- ".rubocop.yml"
|
106
|
-
- ".travis.yml"
|
107
99
|
- CODE_OF_CONDUCT.md
|
108
100
|
- Gemfile
|
109
101
|
- LICENSE.txt
|
@@ -125,7 +117,7 @@ homepage: https://github.com/bjmllr/better_ipaddr
|
|
125
117
|
licenses:
|
126
118
|
- GPL-3.0
|
127
119
|
metadata: {}
|
128
|
-
post_install_message:
|
120
|
+
post_install_message:
|
129
121
|
rdoc_options: []
|
130
122
|
require_paths:
|
131
123
|
- lib
|
@@ -140,9 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
132
|
- !ruby/object:Gem::Version
|
141
133
|
version: '0'
|
142
134
|
requirements: []
|
143
|
-
|
144
|
-
|
145
|
-
signing_key:
|
135
|
+
rubygems_version: 3.3.7
|
136
|
+
signing_key:
|
146
137
|
specification_version: 4
|
147
138
|
summary: IPAddr enhancements for network management.
|
148
139
|
test_files: []
|
data/.travis.yml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.0.0
|
4
|
-
- 2.1.10
|
5
|
-
- 2.2.10
|
6
|
-
- 2.3.7
|
7
|
-
- 2.4.4
|
8
|
-
- 2.5.1
|
9
|
-
- jruby-9.1.16.0
|
10
|
-
matrix:
|
11
|
-
include:
|
12
|
-
- rvm: jruby
|
13
|
-
env: JRUBY_OPTS='-Xcompat.version=2.0'
|
14
|
-
before_install:
|
15
|
-
- if [ "jruby" != "$TRAVIS_RUBY_VERSION" ]; then gem install bundler; fi
|