iprange 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/iprange.rb +10 -4
- data/lib/iprange/version.rb +1 -1
- data/spec/iprange_spec.rb +15 -0
- metadata +15 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: af5afe44bc65284d1801beab8b3dacf81773b151c535eaf354a4e6f3d3f241c3
|
4
|
+
data.tar.gz: f99758acb9dbaeb69f70cd0f23290f361244f28c27fe5180ec51d80385969512
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 465610649a517b9516533cae8080b52f13333efbec0433cbf30b3d63e82984d49a33d3098ca375f93875efd46a321f67e0882c49603a80537278a7cee47400d9
|
7
|
+
data.tar.gz: 774d3e8c2c618709bd2f56b76251b0cabb048ff6b58b6a632711b5a43365020ad39a3d73c4b4fdf4bd1038cd2ce42ddf7818958795b544653d5453130dadb49f
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ If your intervals do not, you can try the tag v0.0.1, which uses sorted sets ins
|
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
|
-
1. Fork it ( http://github.com/
|
35
|
+
1. Fork it ( http://github.com/globocom/iprange/fork )
|
36
36
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
37
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
38
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/iprange.rb
CHANGED
@@ -10,15 +10,21 @@ module IPRange
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def remove(range)
|
13
|
-
@redis.
|
14
|
-
|
13
|
+
@redis.pipelined do
|
14
|
+
@redis.irem(@redis_key, range)
|
15
|
+
@redis.del(metadata_key(range))
|
16
|
+
end
|
15
17
|
end
|
16
18
|
|
17
19
|
def add(range, metadata={})
|
18
20
|
ipaddr_range = IPAddr.new(range).to_range
|
19
|
-
|
21
|
+
range = "#{metadata[:key]}:#{range}" if metadata[:key]
|
20
22
|
hash = metadata_key(range)
|
21
|
-
|
23
|
+
|
24
|
+
@redis.pipelined do
|
25
|
+
@redis.iadd(@redis_key, ipaddr_range.first.to_i, ipaddr_range.last.to_i, range)
|
26
|
+
@redis.mapped_hmset(hash, metadata) unless metadata.empty?
|
27
|
+
end
|
22
28
|
end
|
23
29
|
|
24
30
|
def find(ip)
|
data/lib/iprange/version.rb
CHANGED
data/spec/iprange_spec.rb
CHANGED
@@ -66,6 +66,21 @@ describe IPRange::Range do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
describe "when a range is added with extra key" do
|
70
|
+
after :each do
|
71
|
+
range = IPRange::Range.new()
|
72
|
+
range.remove("router1:192.168.0.1/24")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should find it with the key" do
|
76
|
+
range = IPRange::Range.new
|
77
|
+
range.add("192.168.0.1/24", key: "router1")
|
78
|
+
|
79
|
+
response = range.find("192.168.0.20")
|
80
|
+
expect(response[:range]).to eq("router1:192.168.0.1/24")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
69
84
|
describe "when there is multiple ranges with overlap" do
|
70
85
|
subject do
|
71
86
|
IPRange::Range.new
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iprange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juarez Bochi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.5'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Save IP ranges on Redis for fast lookup using interval sets.
|
@@ -73,8 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .rspec
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
78
|
- Gemfile
|
79
79
|
- LICENSE.txt
|
80
80
|
- README.md
|
@@ -102,17 +102,16 @@ require_paths:
|
|
102
102
|
- lib
|
103
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
|
-
- -
|
105
|
+
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
|
-
- -
|
110
|
+
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
|
-
|
115
|
-
rubygems_version: 2.0.14
|
114
|
+
rubygems_version: 3.0.3
|
116
115
|
signing_key:
|
117
116
|
specification_version: 4
|
118
117
|
summary: IP ranges on Redis
|