diff --git a/.github/workflows/ruby.yaml b/.github/workflows/ruby.yaml new file mode 100644 index 0000000..dbe3313 --- /dev/null +++ b/.github/workflows/ruby.yaml @@ -0,0 +1,28 @@ +name: Ruby CI + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + ruby-version: ["3.2", "3.1", "3.0", "2.7", "2.6"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1.134.0 + with: + ruby-version: ${{ matrix.ruby-version }} + - name: Install dependencies + run: bundle install + - name: Run tests + run: bundle exec rake + - name: rubocop + run: bundle exec rubocop diff --git a/.rubocop.yml b/.rubocop.yml index 9045fdc..0ebf1a8 100755 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,8 @@ +AllCops: + TargetRubyVersion: "2.6" + Exclude: + - "benchmark/**/*" + - "tmp/**/*" StringLiterals: Enabled: false SupportedStyles: @@ -6,3 +11,5 @@ StringLiterals: LineLength: Enabled: true Max: 100 +Style/AccessModifierDeclarations: + Enabled: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 995f716..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: ruby -rvm: - - "2.0.0-p648" - - "2.1.10" - - "2.2.9" - - "2.3.6" - - "2.4.3" - - "2.5.0" -script: - - bundle exec rake - - bundle exec rubocop diff --git a/Gemfile b/Gemfile index e777066..99607f3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in ipconverter.gemspec diff --git a/Rakefile b/Rakefile index 3f3d881..7f9c868 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rake/testtask' require 'rake/extensiontask' -ROOT = File.expand_path('..', __FILE__) +ROOT = File.expand_path(__dir__) Rake::TestTask.new do |t| t.libs << 'test' @@ -10,7 +12,7 @@ Rake::TestTask.new do |t| end Rake::ExtensionTask.new 'ipconverter' do |ext| - ext.lib_dir = 'lib/ipconverter' + ext.lib_dir = File.join %w[lib ipconverter] end task default: %i[compile test] diff --git a/benchmark/int_to_str.rb b/benchmark/int_to_str.rb index 40428f2..8072d3f 100755 --- a/benchmark/int_to_str.rb +++ b/benchmark/int_to_str.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'benchmark' require 'ipaddr' require 'ipconverter' diff --git a/benchmark/str_to_int.rb b/benchmark/str_to_int.rb index 73e8e0c..b83216e 100755 --- a/benchmark/str_to_int.rb +++ b/benchmark/str_to_int.rb @@ -1,12 +1,13 @@ +# frozen_string_literal: true + require 'benchmark' require 'ipaddr' require 'ipconverter' def self.pack_unpack(ip) - ip.split('.').collect(&:to_i).pack('C*').unpack('N').first + ip.split('.').collect(&:to_i).pack('C*').unpack1('N') end -# rubocop:disable AbcSize def self.split_multiply(ip) octets = ip.split('.').map(&:to_i) octets[3] + @@ -14,7 +15,6 @@ def self.split_multiply(ip) octets[1] * 256 * 256 + octets[0] * 256 * 256 * 256 end -# rubocop:enable AbcSize def self.ipaddr_to_i(ip) IPAddr.new(ip).to_i diff --git a/ext/ipconverter/extconf.rb b/ext/ipconverter/extconf.rb index b9f1697..c7fc9ba 100644 --- a/ext/ipconverter/extconf.rb +++ b/ext/ipconverter/extconf.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + require 'mkmf' extension_name = 'ipconverter' dir_config(extension_name) -create_makefile(extension_name) +create_makefile("ipconverter/ipconverter") diff --git a/ipconverter.gemspec b/ipconverter.gemspec index 7425e48..04f7ec3 100644 --- a/ipconverter.gemspec +++ b/ipconverter.gemspec @@ -1,6 +1,7 @@ +# frozen_string_literal: true -lib = File.expand_path('../lib', __FILE__) -ext = File.expand_path('../ext', __FILE__) +lib = File.expand_path('lib', __dir__) +ext = File.expand_path('ext', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) $LOAD_PATH.unshift(ext) unless $LOAD_PATH.include?(ext) require 'ipconverter/version' @@ -16,15 +17,17 @@ string to integer' spec.homepage = 'http://github.com/joshuawscott/ipconverter' spec.license = 'MIT' + spec.required_ruby_version = ">= 2.6.0" + spec.files = `git ls-files -z`.split("\x0") spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.extensions = ['ext/ipconverter/extconf.rb'] spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = %w[lib ext] - spec.add_development_dependency 'bundler', '~> 1.6' + spec.add_development_dependency 'bundler' spec.add_development_dependency 'minitest', '~> 5' - spec.add_development_dependency 'rake', '~> 12.3' + spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rake-compiler', '~> 1.0' spec.add_development_dependency 'rubocop', '~> 0.50' end diff --git a/lib/ipconverter.rb b/lib/ipconverter.rb index ed637e7..e9a4da2 100644 --- a/lib/ipconverter.rb +++ b/lib/ipconverter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ipconverter/version' require 'ipconverter/ipconverter' diff --git a/lib/ipconverter/version.rb b/lib/ipconverter/version.rb index 671e012..a84d636 100644 --- a/lib/ipconverter/version.rb +++ b/lib/ipconverter/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module IpConverter - VERSION = '0.3.1'.freeze + VERSION = '0.4.0' end diff --git a/test/test_ipconverter.rb b/test/test_ipconverter.rb index 5ad049c..a2102dc 100644 --- a/test/test_ipconverter.rb +++ b/test/test_ipconverter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'ipconverter' require 'minitest/autorun'