ext_ipaddr 0.1.0 → 0.1.1
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 +4 -4
- data/.travis.yml +2 -0
- data/README.md +42 -8
- data/ext_ipaddr.gemspec +3 -2
- data/lib/ext_ipaddr.rb +2 -2
- data/lib/ext_ipaddr/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eea797206f51f6fa299d481abbc27ae74673aa9c
|
4
|
+
data.tar.gz: c839320f6dee41c947c6620448cadbaad19cbd7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1be9cbf914fe405b1ec39372a5df49887c303b1befefd5b42a480b1203ae28716aa507e69442ac7078fee5f165d171342a985de1f8bdb0e605ece634a1042fb8
|
7
|
+
data.tar.gz: 84dd39e7f48da2bda984c72140a65d457b96d42ce86c58cef0c9e3474565a75590aecaba69f57fe0bb03a97988293710beac01c10378ea888cb5a4bf3d3273aa
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,27 @@
|
|
1
1
|
# ExtIPAddr
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/ext_ipaddr)
|
4
|
+
[](https://travis-ci.org/s2ugimot/ext_ipaddr)
|
5
|
+
|
6
|
+
Monkey patch for ruby built-in IPAddr class to make it support CIDR notation.
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
IPAddr.new('192.0.2.1/24')
|
10
|
+
# => #<IPAddr: IPv4:192.0.2.1/255.255.255.0>
|
11
|
+
|
12
|
+
IPAddr.new('2001:db8::1/64')
|
13
|
+
# => #<IPAddr: IPv6:2001:0db8:0000:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:0000:0000:0000:0000>
|
14
|
+
```
|
15
|
+
|
16
|
+
|
17
|
+
## Why we need this?
|
18
|
+
|
19
|
+
This gem is intended to use with ActiveRecord and PostgreSQL.
|
20
|
+
With this gem installed, you can store IP address with prefix length information (e.g. "192.0.2.1/24", "2001:db8::1/64") into inet type columns.
|
21
|
+
|
22
|
+
ActiveRecord itself supports PostgreSQL inet type since Rails 4, but it maps to ruby built-in IPAddr class which does not support CIDR notation by default.
|
23
|
+
This gem enables it by tweaking IPAddr class.
|
4
24
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
25
|
|
7
26
|
## Installation
|
8
27
|
|
@@ -20,17 +39,32 @@ Or install it yourself as:
|
|
20
39
|
|
21
40
|
$ gem install ext_ipaddr
|
22
41
|
|
42
|
+
|
23
43
|
## Usage
|
24
44
|
|
25
|
-
|
45
|
+
```ruby
|
46
|
+
require 'ext_ipaddr'
|
47
|
+
|
48
|
+
IPAddr.new('192.0.2.1/24')
|
49
|
+
# => #<IPAddr: IPv4:192.0.2.1/255.255.255.0>
|
26
50
|
|
27
|
-
|
51
|
+
IPAddr.new('2001:db8::1/64')
|
52
|
+
# => #<IPAddr: IPv6:2001:0db8:0000:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:0000:0000:0000:0000>
|
28
53
|
|
29
|
-
|
54
|
+
IPAddr.new('2001:db8::1/64').to_cidr_s
|
55
|
+
# => "2001:db8::1/64"
|
30
56
|
|
31
|
-
|
57
|
+
IPAddr.new('2001:db8::1/64').prefix_length
|
58
|
+
# => 64
|
32
59
|
|
33
|
-
|
60
|
+
IPAddr.new('192.0.2.1/24') == IPAddr.new('192.0.2.1/24')
|
61
|
+
# => true
|
34
62
|
|
35
|
-
|
63
|
+
IPAddr.new('192.0.2.1/24') == IPAddr.new('192.0.2.1/32')
|
64
|
+
# => false
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
## Contributing
|
36
69
|
|
70
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/s2ugimot/ext_ipaddr
|
data/ext_ipaddr.gemspec
CHANGED
@@ -8,9 +8,10 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = ExtIPAddr::VERSION
|
9
9
|
spec.authors = ["Shu Sugimoto"]
|
10
10
|
spec.email = ["shu@su.gimo.to"]
|
11
|
+
spec.licenses = ['MIT']
|
11
12
|
|
12
|
-
spec.summary = %q{Monkey patch for built-in IPAddr class
|
13
|
-
spec.description = %q{Monkey patch for built-in IPAddr class
|
13
|
+
spec.summary = %q{Monkey patch for ruby built-in IPAddr class to make it support CIDR notation}
|
14
|
+
spec.description = %q{Monkey patch for ruby built-in IPAddr class to make it support CIDR notation}
|
14
15
|
spec.homepage = "https://github.com/s2ugimot/ext_ipaddr"
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
data/lib/ext_ipaddr.rb
CHANGED
@@ -29,7 +29,7 @@ IPAddr.class_eval do
|
|
29
29
|
IPAddr.new(@mask_addr, @family)
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def prefix_length
|
33
33
|
begin_addr = (@addr & @mask_addr)
|
34
34
|
|
35
35
|
case @family
|
@@ -45,7 +45,7 @@ IPAddr.class_eval do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def to_cidr_s
|
48
|
-
return to_s + "/#{
|
48
|
+
return to_s + "/#{prefix_length}"
|
49
49
|
end
|
50
50
|
|
51
51
|
def ==(other)
|
data/lib/ext_ipaddr/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ext_ipaddr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shu Sugimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: Monkey patch for ruby built-in IPAddr class to make it support CIDR notation
|
70
70
|
email:
|
71
71
|
- shu@su.gimo.to
|
72
72
|
executables: []
|
@@ -85,7 +85,8 @@ files:
|
|
85
85
|
- lib/ext_ipaddr.rb
|
86
86
|
- lib/ext_ipaddr/version.rb
|
87
87
|
homepage: https://github.com/s2ugimot/ext_ipaddr
|
88
|
-
licenses:
|
88
|
+
licenses:
|
89
|
+
- MIT
|
89
90
|
metadata: {}
|
90
91
|
post_install_message:
|
91
92
|
rdoc_options: []
|
@@ -103,8 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
version: '0'
|
104
105
|
requirements: []
|
105
106
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.2.2
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
|
-
summary:
|
110
|
+
summary: Monkey patch for ruby built-in IPAddr class to make it support CIDR notation
|
110
111
|
test_files: []
|