ip-ranges 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,13 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
+
2
3
  gem "netaddr"
3
- gem "rdoc"
4
- gem "rspec"
4
+
5
+ group :development, :test do
6
+ gem "rdoc"
7
+ gem "rdoc-data"
8
+ gem "rake"
9
+ gem "gem-this"
10
+ gem "gemcutter"
11
+ gem "rspec"
12
+ gem "ruby-debug"
13
+ end
@@ -1,9 +1,18 @@
1
1
  GEM
2
- remote: http://rubygems.org/
2
+ remote: https://rubygems.org/
3
3
  specs:
4
+ columnize (0.8.9)
4
5
  diff-lcs (1.1.3)
6
+ gem-this (0.3.7)
7
+ gemcutter (0.7.1)
8
+ linecache (0.46)
9
+ rbx-require-relative (> 0.0.4)
5
10
  netaddr (1.5.0)
11
+ rake (10.3.2)
12
+ rbx-require-relative (0.0.9)
6
13
  rdoc (3.9.4)
14
+ rdoc-data (3.12)
15
+ rdoc (> 2.5, < 4.0)
7
16
  rspec (2.6.0)
8
17
  rspec-core (~> 2.6.0)
9
18
  rspec-expectations (~> 2.6.0)
@@ -12,11 +21,21 @@ GEM
12
21
  rspec-expectations (2.6.0)
13
22
  diff-lcs (~> 1.1.2)
14
23
  rspec-mocks (2.6.0)
24
+ ruby-debug (0.10.4)
25
+ columnize (>= 0.1)
26
+ ruby-debug-base (~> 0.10.4.0)
27
+ ruby-debug-base (0.10.4)
28
+ linecache (>= 0.3)
15
29
 
16
30
  PLATFORMS
17
31
  ruby
18
32
 
19
33
  DEPENDENCIES
34
+ gem-this
35
+ gemcutter
20
36
  netaddr
37
+ rake
21
38
  rdoc
39
+ rdoc-data
22
40
  rspec
41
+ ruby-debug
File without changes
data/Rakefile CHANGED
@@ -12,6 +12,21 @@ task :spec do
12
12
  system "bundle exec rspec spec/*_spec.rb spec/**/*_spec.rb"
13
13
  end
14
14
 
15
+
16
+
17
+ require "rubygems"
18
+ require "rubygems/package_task"
19
+ require "rdoc/task"
20
+
21
+ require "rspec"
22
+ require "rspec/core/rake_task"
23
+ RSpec::Core::RakeTask.new do |t|
24
+ t.rspec_opts = %w(--format documentation --colour)
25
+ end
26
+
27
+
28
+ task :default => ["spec"]
29
+
15
30
  # This builds the actual gem. For details of what all these options
16
31
  # mean, and other ones you can add, check the documentation here:
17
32
  #
@@ -21,18 +36,17 @@ spec = Gem::Specification.new do |s|
21
36
 
22
37
  # Change these as appropriate
23
38
  s.name = "ip-ranges"
24
- s.version = "0.1.1"
25
- s.summary = "Manage ranges of IP numbers determining equivalence, containment and overlaps"
39
+ s.version = "0.1.2"
40
+ s.summary = "Compare and manipulate ranges of IP numbers"
26
41
  s.author = "David Salgado"
27
42
  s.email = "david@digitalronin.com"
28
- s.homepage = "http://roninonrails.wordpress.com/2011/09/10/ip-ranges-gem/"
43
+ s.homepage = "https://digitalronin.github.io/2011/09/10/ip-ranges-gem/"
29
44
 
30
45
  s.has_rdoc = true
31
- s.description = "Compare multiple IP ranges for overlaps, equivalence and containment"
32
- # s.extra_rdoc_files = %w(README)
33
- s.rdoc_options = %w(-x pkg)
46
+ s.extra_rdoc_files = %w(README.markdown)
47
+ s.rdoc_options = %w(--main README.markdown)
34
48
 
35
- # Add any extra files to include in the gem (like your README)
49
+ # Add any extra files to include in the gem
36
50
  s.files = %w(Gemfile Gemfile.lock Rakefile README.markdown) + Dir.glob("{spec,lib}/**/*")
37
51
  s.require_paths = ["lib"]
38
52
 
@@ -42,7 +56,7 @@ spec = Gem::Specification.new do |s|
42
56
 
43
57
  # If your tests use any gems, include them here
44
58
  s.add_development_dependency("rspec")
45
- s.add_development_dependency("rdoc")
59
+ s.add_development_dependency("ruby-debug")
46
60
  end
47
61
 
48
62
  # This task actually builds the gem. We also regenerate a static
@@ -50,7 +64,7 @@ end
50
64
  # be automatically building a gem for this project. If you're not
51
65
  # using GitHub, edit as appropriate.
52
66
  #
53
- # To publish your gem online, install the 'gemcutter' gem; Read more
67
+ # To publish your gem online, install the 'gemcutter' gem; Read more
54
68
  # about that here: http://gemcutter.org/pages/gem_docs
55
69
  Gem::PackageTask.new(spec) do |pkg|
56
70
  pkg.gem_spec = spec
@@ -71,8 +85,8 @@ task :package => :gemspec
71
85
 
72
86
  # Generate documentation
73
87
  RDoc::Task.new do |rd|
74
-
75
- rd.rdoc_files.include("lib/**/*.rb")
88
+ rd.main = "README.markdown"
89
+ rd.rdoc_files.include("README.markdown", "lib/**/*.rb")
76
90
  rd.rdoc_dir = "rdoc"
77
91
  end
78
92
 
@@ -80,3 +94,24 @@ desc 'Clear out RDoc and generated packages'
80
94
  task :clean => [:clobber_rdoc, :clobber_package] do
81
95
  rm "#{spec.name}.gemspec"
82
96
  end
97
+
98
+ desc 'Tag the repository in git with gem version number'
99
+ task :tag => [:gemspec, :package] do
100
+ if `git diff --cached`.empty?
101
+ if `git tag`.split("\n").include?("v#{spec.version}")
102
+ raise "Version #{spec.version} has already been released"
103
+ end
104
+ `git add #{File.expand_path("../#{spec.name}.gemspec", __FILE__)}`
105
+ `git commit -m "Released version #{spec.version}"`
106
+ `git tag v#{spec.version}`
107
+ `git push --tags`
108
+ `git push`
109
+ else
110
+ raise "Unstaged changes still waiting to be committed"
111
+ end
112
+ end
113
+
114
+ desc "Tag and publish the gem to rubygems.org"
115
+ task :publish => :tag do
116
+ `gem push pkg/#{spec.name}-#{spec.version}.gem`
117
+ end
File without changes
File without changes
@@ -51,6 +51,21 @@ module IpRanges
51
51
  end
52
52
  end
53
53
 
54
+ # Arguments
55
+ # * An +Ip+ object
56
+ # Extend the range if the pushed IP is the next, contiguous ip in the range. Otherwise return false and do nothing.
57
+ def push(ip)
58
+ if empty?
59
+ @first = ip
60
+ true
61
+ elsif ip.to_s == @last.dup.increment
62
+ @last = ip
63
+ true
64
+ else
65
+ false
66
+ end
67
+ end
68
+
54
69
  # Returns the last Ip object in this range.
55
70
  def last
56
71
  @last
@@ -103,6 +118,10 @@ module IpRanges
103
118
 
104
119
  private
105
120
 
121
+ def empty?
122
+ @first.nil? && @last.nil?
123
+ end
124
+
106
125
  def throttle
107
126
  @counter += 1
108
127
  if @counter % BATCHSIZE == 0
File without changes
@@ -4,6 +4,83 @@ describe IpRanges::Range do
4
4
  before do
5
5
  end
6
6
 
7
+ context "pushing" do
8
+ let(:ip1) { IpRanges::Ip.new(:number => '1.1.1.1') }
9
+ let(:ip2) { IpRanges::Ip.new(:number => '1.1.1.2') }
10
+ let(:ip3) { IpRanges::Ip.new(:number => '1.1.1.3') }
11
+ let(:ip4) { IpRanges::Ip.new(:number => '1.1.1.4') }
12
+
13
+ context "empty range" do
14
+ let(:empty) { described_class.new(:range => '') }
15
+
16
+ it "pushes" do
17
+ res = empty.push(ip1)
18
+ res.should be_true
19
+ end
20
+
21
+ it "sets first ip" do
22
+ empty.push(ip1)
23
+ empty.first.should eq(ip1)
24
+ end
25
+ end
26
+
27
+ context "range with start" do
28
+ let(:r1) { described_class.new(:range => ip1.to_s) }
29
+
30
+ context "pushing next ip" do
31
+ it "pushes" do
32
+ res = r1.push(ip2)
33
+ res.should be_true
34
+ end
35
+
36
+ it "sets last ip" do
37
+ r1.push(ip2)
38
+ r1.last.should eq(ip2)
39
+ end
40
+ end
41
+
42
+ context "pushing non-contiguous ip" do
43
+ it "doesn't push" do
44
+ res = r1.push(ip3)
45
+ res.should be_false
46
+ end
47
+
48
+ it "doesn't set last ip" do
49
+ r1.push(ip3)
50
+ r1.last.should eq(r1.first)
51
+ end
52
+ end
53
+ end
54
+
55
+ context "range with start and end" do
56
+ let(:range) { described_class.new(:range => [ip1.to_s, ip2.to_s].join('..')) }
57
+
58
+ context "pushing next ip" do
59
+ it "pushes" do
60
+ res = range.push(ip3)
61
+ res.should be_true
62
+ end
63
+
64
+ it "sets last ip" do
65
+ range.push(ip3)
66
+ range.last.should eq(ip3)
67
+ end
68
+ end
69
+
70
+ context "pushing non-contiguous ip" do
71
+ it "doesn't push" do
72
+ res = range.push(ip4)
73
+ res.should be_false
74
+ end
75
+
76
+ it "doesn't set last ip" do
77
+ range.push(ip4)
78
+ range.last.should eq(ip2)
79
+ end
80
+ end
81
+ end
82
+ end
83
+
7
84
  context "checking for overlaps" do
8
85
 
9
86
  it "knows when range a contains range b" do
File without changes
@@ -1 +1,4 @@
1
+ require 'ruby-debug'
2
+ Debugger.start
3
+
1
4
  require 'lib/ip-ranges'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ip-ranges
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Salgado
@@ -15,12 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-10 00:00:00 Z
18
+ date: 2014-08-03 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: netaddr
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
21
+ type: :runtime
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
23
  none: false
25
24
  requirements:
26
25
  - - ~>
@@ -31,12 +30,12 @@ dependencies:
31
30
  - 5
32
31
  - 0
33
32
  version: 1.5.0
34
- type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
33
+ requirement: *id001
38
34
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ name: netaddr
36
+ - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ">="
@@ -45,12 +44,12 @@ dependencies:
45
44
  segments:
46
45
  - 0
47
46
  version: "0"
48
- type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: rdoc
47
+ requirement: *id002
52
48
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
49
+ name: rspec
50
+ - !ruby/object:Gem::Dependency
51
+ type: :development
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
53
  none: false
55
54
  requirements:
56
55
  - - ">="
@@ -59,16 +58,17 @@ dependencies:
59
58
  segments:
60
59
  - 0
61
60
  version: "0"
62
- type: :development
63
- version_requirements: *id003
64
- description: Compare multiple IP ranges for overlaps, equivalence and containment
61
+ requirement: *id003
62
+ prerelease: false
63
+ name: ruby-debug
64
+ description:
65
65
  email: david@digitalronin.com
66
66
  executables: []
67
67
 
68
68
  extensions: []
69
69
 
70
- extra_rdoc_files: []
71
-
70
+ extra_rdoc_files:
71
+ - README.markdown
72
72
  files:
73
73
  - Gemfile
74
74
  - Gemfile.lock
@@ -81,13 +81,13 @@ files:
81
81
  - lib/ip-ranges/ip.rb
82
82
  - lib/ip-ranges/range.rb
83
83
  - lib/ip-ranges.rb
84
- homepage: http://roninonrails.wordpress.com/2011/09/10/ip-ranges-gem/
84
+ homepage: https://digitalronin.github.io/2011/09/10/ip-ranges-gem/
85
85
  licenses: []
86
86
 
87
87
  post_install_message:
88
88
  rdoc_options:
89
- - -x
90
- - pkg
89
+ - --main
90
+ - README.markdown
91
91
  require_paths:
92
92
  - lib
93
93
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -111,9 +111,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements: []
112
112
 
113
113
  rubyforge_project:
114
- rubygems_version: 1.8.10
114
+ rubygems_version: 1.8.25
115
115
  signing_key:
116
116
  specification_version: 3
117
- summary: Manage ranges of IP numbers determining equivalence, containment and overlaps
117
+ summary: Compare and manipulate ranges of IP numbers
118
118
  test_files: []
119
119