ipconverter 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 35d504928af695671d8144143e89352318257797
4
- data.tar.gz: 2209fc9ad9a7198c04e7432f1082dfc9baa49467
2
+ SHA256:
3
+ metadata.gz: 54ad3d7a1a322566c642df08f51b0f86b041dd0a112a30f14162b6405a3c134a
4
+ data.tar.gz: b0a2978036a14dde903662be197e151e87b762474e1127075d237c655893d9c8
5
5
  SHA512:
6
- metadata.gz: 801b267b6b1316cc979a26d78662d0ecef5579aa160c90925488174783af33920eef1c7e3d1b7c164fe3126f646e561dabf8ff937d7d0c79ac656c3ea69d5789
7
- data.tar.gz: 8a39dd4ec289ae550de076791d58ce113886baa4602091d302f7b13fcf32f3fca765cc68f9f40dca3267742b31ec4c59940222cf02bc7e0b5143eb201c348e39
6
+ metadata.gz: 19e0ed781d197381e9a5f223561350d295e9bc697faa62d312a0faf0af8b00621db0976b49674739a2ba4e235b45f6060e6a5c47dfa0b669733d1d54e4dbfbf3
7
+ data.tar.gz: 7655da0d139a1e0aec61f43093334d5c449110ba95c2be9a5d16a366ebb49339eddf6eada918e46ad6085a6b5927189a6dac96cad8bb50ffdab5d071d5fcbc38
@@ -0,0 +1,28 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ ruby-version: ["3.2", "3.1", "3.0", "2.7", "2.6"]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v3
19
+ - name: Set up Ruby ${{ matrix.ruby-version }}
20
+ uses: ruby/setup-ruby@v1.134.0
21
+ with:
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ - name: Install dependencies
24
+ run: bundle install
25
+ - name: Run tests
26
+ run: bundle exec rake
27
+ - name: rubocop
28
+ run: bundle exec rubocop
data/.rubocop.yml ADDED
@@ -0,0 +1,15 @@
1
+ AllCops:
2
+ TargetRubyVersion: "2.6"
3
+ Exclude:
4
+ - "benchmark/**/*"
5
+ - "tmp/**/*"
6
+ StringLiterals:
7
+ Enabled: false
8
+ SupportedStyles:
9
+ - single_quotes
10
+ - double_quotes
11
+ LineLength:
12
+ Enabled: true
13
+ Max: 100
14
+ Style/AccessModifierDeclarations:
15
+ Enabled: false
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ lib/**/*.rb ext/**/*.c README
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in ipconverter.gemspec
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # IpConverter
2
2
 
3
+ [![Build Status](https://travis-ci.org/joshuawscott/ipconverter.svg?branch=master)](https://travis-ci.org/joshuawscott/ipconverter)
4
+
3
5
  Library to deal with IP Address conversions/manipulation, such as converting
4
6
  a string representation like "192.168.2.1" to its integer representation
5
7
  (3232236033)
6
8
 
7
- Tested with Ruby >= 1.9.3.
9
+ Tested with Ruby >= 2.0
8
10
 
9
11
  ## Installation
10
12
 
data/Rakefile CHANGED
@@ -1,14 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
  require 'rake/extensiontask'
4
6
 
7
+ ROOT = File.expand_path(__dir__)
8
+
5
9
  Rake::TestTask.new do |t|
6
10
  t.libs << 'test'
7
11
  t.pattern = 'test/test_*.rb'
8
12
  end
9
13
 
10
14
  Rake::ExtensionTask.new 'ipconverter' do |ext|
11
- ext.lib_dir = 'lib/ipconverter'
15
+ ext.lib_dir = File.join %w[lib ipconverter]
12
16
  end
13
17
 
14
- task default: [:compile, :test]
18
+ task default: %i[compile test]
19
+
20
+ desc "Run benchmarks"
21
+ task benchmark: [:compile] do
22
+ sh "ruby #{ROOT}/benchmark/str_to_int.rb"
23
+ sh "ruby #{ROOT}/benchmark/int_to_str.rb"
24
+ end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'benchmark'
2
4
  require 'ipaddr'
3
5
  require 'ipconverter'
4
6
 
5
- def ruby_shift(ip)
7
+ def self.ruby_shift(ip)
6
8
  [
7
9
  (ip >> 24) & 255,
8
10
  (ip >> 16) & 255,
@@ -11,13 +13,13 @@ def ruby_shift(ip)
11
13
  ].join('.')
12
14
  end
13
15
 
14
- ips = 0..999999
16
+ ips = 0..999_999
15
17
 
16
18
  puts 'iterations: 1,000,000'
17
19
 
18
20
  Benchmark.bmbm do |x|
19
21
  x.report('IPAddr#to_s') { ips.each { |ip| IPAddr.new(ip, Socket::AF_INET).to_s } }
20
22
  x.report('Ruby shifts') { ips.each { |ip| ruby_shift(ip) } }
21
- x.report('C shifts') { ips.each { |ip| IpConverter.int_to_str(ip) } }
23
+ x.report('IpConverter') { ips.each { |ip| IpConverter.int_to_str(ip) } }
22
24
  x.report('noop') { ips.each { |ip| ip } }
23
25
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'benchmark'
2
4
  require 'ipaddr'
3
5
  require 'ipconverter'
4
6
 
5
- def ip_to_i(ip)
6
- ip.split('.').collect(&:to_i).pack('C*').unpack('N').first
7
+ def self.pack_unpack(ip)
8
+ ip.split('.').collect(&:to_i).pack('C*').unpack1('N')
7
9
  end
8
10
 
9
- def ip_to_i2(ip)
11
+ def self.split_multiply(ip)
10
12
  octets = ip.split('.').map(&:to_i)
11
13
  octets[3] +
12
14
  octets[2] * 256 +
@@ -14,7 +16,7 @@ def ip_to_i2(ip)
14
16
  octets[0] * 256 * 256 * 256
15
17
  end
16
18
 
17
- def ipaddr_to_i(ip)
19
+ def self.ipaddr_to_i(ip)
18
20
  IPAddr.new(ip).to_i
19
21
  end
20
22
 
@@ -33,8 +35,8 @@ puts 'iterations: 1,000,000'
33
35
 
34
36
  Benchmark.bmbm do |x|
35
37
  x.report('IPAddr#to_i') { ips.each { |ip| IPAddr.new(ip).to_i } }
36
- x.report('pack/unpack') { ips.each { |ip| ip_to_i(ip) } }
37
- x.report('split/multiply') { ips.each { |ip| ip_to_i2(ip) } }
38
- x.report('C split/multiply') { ips.each { |ip| IpConverter.str_to_int(ip) } }
38
+ x.report('pack/unpack') { ips.each { |ip| pack_unpack(ip) } }
39
+ x.report('split/multiply') { ips.each { |ip| split_multiply(ip) } }
40
+ x.report('IpConverter') { ips.each { |ip| IpConverter.str_to_int(ip) } }
39
41
  x.report('noop') { ips.each { |ip| ip } }
40
42
  end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mkmf'
2
4
  extension_name = 'ipconverter'
3
5
  dir_config(extension_name)
4
- create_makefile(extension_name)
6
+ create_makefile("ipconverter/ipconverter")
@@ -14,9 +14,9 @@ void Init_ipconverter() {
14
14
 
15
15
  /*
16
16
  * call-seq:
17
- * IpConverter.str_to_int(ip_addr_string) -> Fixnum
17
+ * IpConverter.str_to_int(ip_addr_string) -> Integer
18
18
  *
19
- * Converts the passed IP address String into a Fixnum.
19
+ * Converts the passed IP address String into an Integer.
20
20
  *
21
21
  * Raises ArgumentError if ip address is not valid. Leading and trailing
22
22
  * whitespace is ignored.
@@ -36,7 +36,7 @@ VALUE method_str_to_int(VALUE _module_, VALUE ip_string) {
36
36
  int success = ip_string_to_long(c_string, &result);
37
37
 
38
38
  if (success) {
39
- // Convert the uint32_t back to a ruby Fixnum.
39
+ // Convert the uint32_t back to a ruby Integer.
40
40
  return UINT2NUM(result);
41
41
  } else {
42
42
  rb_raise(rb_eArgError, "Invalid IP Address String");
@@ -86,9 +86,9 @@ ip_string_to_long(char c_string[], uint32_t *result) {
86
86
  *
87
87
  */
88
88
  VALUE
89
- method_int_to_str(VALUE _module_, VALUE ip_fixnum) {
89
+ method_int_to_str(VALUE _module_, VALUE ip_integer) {
90
90
  char c_string[16];
91
- int64_t ip = NUM2LL(ip_fixnum);
91
+ int64_t ip = NUM2LL(ip_integer);
92
92
  if (ip > MAX_IP_INT || ip < 0) {
93
93
  rb_raise(rb_eArgError, "IP address integer out of range");
94
94
  }
data/ipconverter.gemspec CHANGED
@@ -1,6 +1,7 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- ext = File.expand_path('../ext', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ ext = File.expand_path('ext', __dir__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
6
  $LOAD_PATH.unshift(ext) unless $LOAD_PATH.include?(ext)
6
7
  require 'ipconverter/version'
@@ -11,19 +12,22 @@ Gem::Specification.new do |spec|
11
12
  spec.authors = ['Joshua Scott']
12
13
  spec.email = ['joshua.scott@gmail.com']
13
14
  spec.summary = 'Utilities for working with IP addresses'
14
- spec.description = %q(Fast C extension for converting IP addresses from
15
- string to integer)
15
+ spec.description = 'Fast C extension for converting IP addresses from
16
+ string to integer'
16
17
  spec.homepage = 'http://github.com/joshuawscott/ipconverter'
17
18
  spec.license = 'MIT'
18
19
 
20
+ spec.required_ruby_version = ">= 2.6.0"
21
+
19
22
  spec.files = `git ls-files -z`.split("\x0")
20
23
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
24
  spec.extensions = ['ext/ipconverter/extconf.rb']
22
25
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
- spec.require_paths = %w(lib ext)
26
+ spec.require_paths = %w[lib ext]
24
27
 
25
- spec.add_development_dependency 'bundler', '~> 1.6'
26
- spec.add_development_dependency 'rake', '~> 10'
28
+ spec.add_development_dependency 'bundler'
27
29
  spec.add_development_dependency 'minitest', '~> 5'
28
- spec.add_development_dependency 'rake-compiler', '~> 0.9'
30
+ spec.add_development_dependency 'rake', '~> 13.0'
31
+ spec.add_development_dependency 'rake-compiler', '~> 1.0'
32
+ spec.add_development_dependency 'rubocop', '~> 0.50'
29
33
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module IpConverter
2
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
3
5
  end
data/lib/ipconverter.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ipconverter/version'
2
4
  require 'ipconverter/ipconverter'
3
5
 
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ipconverter'
2
4
  require 'minitest/autorun'
3
5
 
4
6
  class TestIpConverter < MiniTest::Test
5
- MAX_IP_INT = 4294967295
6
- def setup
7
- end
7
+ MAX_IP_INT = 4_294_967_295
8
+ def setup; end
8
9
 
9
10
  def test_smallest_ip
10
11
  int = IpConverter.str_to_int '0.0.0.0'
@@ -43,11 +44,11 @@ class TestIpConverter < MiniTest::Test
43
44
  end
44
45
 
45
46
  def test_int_to_str_max
46
- assert_equal "255.255.255.255", IpConverter.int_to_str(MAX_IP_INT)
47
+ assert_equal "255.255.255.255", IpConverter.int_to_str(MAX_IP_INT)
47
48
  end
48
49
 
49
50
  def test_int_to_str_negative
50
- assert_raises(ArgumentError) { IpConverter.int_to_str -1 }
51
+ assert_raises(ArgumentError) { IpConverter.int_to_str(-1) }
51
52
  end
52
53
 
53
54
  def test_int_to_str_too_big
metadata CHANGED
@@ -1,71 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipconverter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Scott
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-22 00:00:00.000000000 Z
11
+ date: 2023-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.6'
33
+ version: '5'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.6'
40
+ version: '5'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '10'
47
+ version: '13.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '10'
54
+ version: '13.0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: minitest
56
+ name: rake-compiler
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '5'
61
+ version: '1.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '5'
68
+ version: '1.0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rake-compiler
70
+ name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0.9'
75
+ version: '0.50'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '0.9'
82
+ version: '0.50'
69
83
  description: |-
70
84
  Fast C extension for converting IP addresses from
71
85
  string to integer
@@ -76,7 +90,10 @@ extensions:
76
90
  - ext/ipconverter/extconf.rb
77
91
  extra_rdoc_files: []
78
92
  files:
93
+ - ".github/workflows/ruby.yaml"
79
94
  - ".gitignore"
95
+ - ".rubocop.yml"
96
+ - ".yardopts"
80
97
  - Gemfile
81
98
  - LICENSE.txt
82
99
  - README.md
@@ -94,7 +111,7 @@ homepage: http://github.com/joshuawscott/ipconverter
94
111
  licenses:
95
112
  - MIT
96
113
  metadata: {}
97
- post_install_message:
114
+ post_install_message:
98
115
  rdoc_options: []
99
116
  require_paths:
100
117
  - lib
@@ -103,18 +120,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
120
  requirements:
104
121
  - - ">="
105
122
  - !ruby/object:Gem::Version
106
- version: '0'
123
+ version: 2.6.0
107
124
  required_rubygems_version: !ruby/object:Gem::Requirement
108
125
  requirements:
109
126
  - - ">="
110
127
  - !ruby/object:Gem::Version
111
128
  version: '0'
112
129
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.2.3
115
- signing_key:
130
+ rubygems_version: 3.2.33
131
+ signing_key:
116
132
  specification_version: 4
117
133
  summary: Utilities for working with IP addresses
118
134
  test_files:
119
135
  - test/test_ipconverter.rb
120
- has_rdoc: