diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a4b0775..14c43be 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: - ruby-version: 3.1 + ruby-version: 3.3 bundler-cache: true # runs 'bundle install' and caches installed gems automatically - name: Lint files with Rubocop run: | diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 6eca420..288224d 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -15,19 +15,16 @@ jobs: os: - ubuntu ruby: - - "2.5" - - "2.6" - - "2.7" - "3.0" - "3.1" - "3.2" - "3.3" - "head" - - "jruby-9.3" + - "jruby-9.4" runs-on: ${{ matrix.os }}-latest continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby ${{ matrix.ruby }} uses: ruby/setup-ruby@v1 with: diff --git a/.rubocop.yml b/.rubocop.yml index 40c8c56..fe705cb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,7 +5,7 @@ inherit_from: .rubocop_todo.yml AllCops: NewCops: enable - TargetRubyVersion: 2.5 + TargetRubyVersion: 3.0 Lint/RaiseException: Enabled: true diff --git a/amazing_print.gemspec b/amazing_print.gemspec index f07b09f..a631a82 100644 --- a/amazing_print.gemspec +++ b/amazing_print.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.description = 'Great Ruby debugging companion: pretty print Ruby objects to visualize their structure. Supports custom object formatting via plugins' s.license = 'MIT' - s.files = Dir['[A-Z]*[^~]'] + Dir['lib/**/*.rb'] + Dir['spec/**/*'] + ['.gitignore'] + s.files = Dir['lib/**/*', 'rails/*', 'CHANGELOG.md', 'CONTRIBUTING.md', 'README.md'] s.executables = [] s.require_paths = ['lib'] end diff --git a/init.rb b/init.rb deleted file mode 100644 index 3c47ab1..0000000 --- a/init.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -require File.join(File.dirname(__FILE__), 'lib', 'amazing_print') diff --git a/lib/amazing_print/ext/nobrainer.rb b/lib/amazing_print/ext/nobrainer.rb index 51bc489..a9e2439 100644 --- a/lib/amazing_print/ext/nobrainer.rb +++ b/lib/amazing_print/ext/nobrainer.rb @@ -32,9 +32,9 @@ def cast_with_nobrainer(object, type) #------------------------------------------------------------------------------ def awesome_nobrainer_class(object) name = "#{awesome_simple(object, :class)} < #{awesome_simple(object.superclass, :class)}" - data = object.fields.map do |field, options| + data = object.fields.to_h do |field, options| [field, (options[:type] || Object).to_s.underscore.to_sym] - end.to_h + end name = "class #{awesome_simple(object.to_s, :class)}" base = "< #{awesome_simple(object.superclass.to_s, :class)}" diff --git a/lib/amazing_print/formatters/mswin_helper.rb b/lib/amazing_print/formatters/mswin_helper.rb index 042a5cd..84e8744 100644 --- a/lib/amazing_print/formatters/mswin_helper.rb +++ b/lib/amazing_print/formatters/mswin_helper.rb @@ -27,10 +27,10 @@ def initialize(fname) def mode r = ['-'] * 6 r[0] = 'd' if @stat.directory? - r[1] = 'a' unless (@attrs & FILE_ATTRIBUTE_ARCHIVE).zero? - r[2] = 'r' unless (@attrs & FILE_ATTRIBUTE_READONLY).zero? - r[3] = 'h' unless (@attrs & FILE_ATTRIBUTE_HIDDEN).zero? - r[4] = 's' unless (@attrs & FILE_ATTRIBUTE_SYSTEM).zero? + r[1] = 'a' unless @attrs.nobits?(FILE_ATTRIBUTE_ARCHIVE) + r[2] = 'r' unless @attrs.nobits?(FILE_ATTRIBUTE_READONLY) + r[3] = 'h' unless @attrs.nobits?(FILE_ATTRIBUTE_HIDDEN) + r[4] = 's' unless @attrs.nobits?(FILE_ATTRIBUTE_SYSTEM) r[5] = 'l' if File.symlink? @fname r.join end diff --git a/lib/amazing_print/formatters/object_formatter.rb b/lib/amazing_print/formatters/object_formatter.rb index 704d95a..c400b5a 100644 --- a/lib/amazing_print/formatters/object_formatter.rb +++ b/lib/amazing_print/formatters/object_formatter.rb @@ -17,7 +17,7 @@ def initialize(object, inspector) def format vars = variables.map do |var| - property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet. + property = var.to_s[1..].to_sym # to_s because of some monkey patching done by Puppet. accessor = if object.respond_to?(:"#{property}=") object.respond_to?(property) ? :accessor : :writer else diff --git a/lib/amazing_print/formatters/struct_formatter.rb b/lib/amazing_print/formatters/struct_formatter.rb index c239410..4697d70 100644 --- a/lib/amazing_print/formatters/struct_formatter.rb +++ b/lib/amazing_print/formatters/struct_formatter.rb @@ -17,7 +17,7 @@ def initialize(struct, inspector) def format vars = variables.map do |var| - property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet. + property = var.to_s[1..].to_sym # to_s because of some monkey patching done by Puppet. accessor = if struct.respond_to?(:"#{property}=") struct.respond_to?(property) ? :accessor : :writer else diff --git a/rails/init.rb b/rails/init.rb deleted file mode 100644 index 8e93e99..0000000 --- a/rails/init.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -# Copyright (c) 2010-2016 Michael Dvorkin and contributors -# -# AmazingPrint is freely distributable under the terms of MIT license. -# See LICENSE file or http://www.opensource.org/licenses/mit-license.php -#------------------------------------------------------------------------------ -# -# Load amazing_print when installed as Rails 2.3.x plugin. -# -require File.join(File.dirname(__FILE__), '..', 'init') unless defined?(AmazingPrint) diff --git a/spec/core_ext/logger_spec.rb b/spec/core_ext/logger_spec.rb index 0fdf76f..4adafa5 100644 --- a/spec/core_ext/logger_spec.rb +++ b/spec/core_ext/logger_spec.rb @@ -7,9 +7,9 @@ RSpec.describe 'AmazingPrint logging extensions' do subject(:logger) do - Logger.new('/dev/null') + Logger.new(File::NULL) rescue Errno::ENOENT - Logger.new('nul') + Logger.new(File::NULL) end let(:object) { double } diff --git a/spec/ext/active_record_spec.rb b/spec/ext/active_record_spec.rb index 35ac41c..4955636 100644 --- a/spec/ext/active_record_spec.rb +++ b/spec/ext/active_record_spec.rb @@ -136,7 +136,7 @@ ActiveRecordData.raw_3_2_diana end - if RUBY_PLATFORM == 'java' && !activerecord_6_1? + if RUBY_PLATFORM == 'java' && !activerecord_6_1? && !activerecord_7_0? raw_object_string.gsub!( 'ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer', 'ArJdbc::SQLite3::SQLite3Integer' @@ -172,7 +172,7 @@ ActiveRecordData.raw_3_2_multi end - if RUBY_PLATFORM == 'java' && !activerecord_6_1? + if RUBY_PLATFORM == 'java' && !activerecord_6_1? && !activerecord_7_0? raw_object_string.gsub!( 'ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer', 'ArJdbc::SQLite3::SQLite3Integer' @@ -238,7 +238,7 @@ class SubUser < User { if ActiveRecord::VERSION::STRING >= '3.2' if RUBY_PLATFORM == 'java' expect(out).to match( - /\s+first\(\*args,\s&block\)\s+#\s+\(ActiveRecord::Querying\)/ + /\s+first\(\*\*,\s\?, &&\)\s+#= Gem::Version.new('3.1.0') expect(out).to match( @@ -267,7 +267,7 @@ class SubUser < User { out = @ap.awesome(User.methods.grep(/primary_key/)) if RUBY_PLATFORM == 'java' expect(out).to match( - /\sprimary_key\(.*?\)\s+#\s\(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/ + /\sprimary_key\(\)\s+#= Gem::Version.new('3.0.0') expect(out).to match(/\sprimary_key\(.*?\)\s+# \(ActiveRecord::AttributeMethods::PrimaryKey::ClassMethods\)/) @@ -287,7 +287,7 @@ class SubUser < User { if ActiveRecord::VERSION::MAJOR < 3 expect(out).to match(/\svalidate\(\*arg.*?\)\s+User \(ActiveRecord::Base\)/) elsif RUBY_PLATFORM == 'java' - expect(out).to match(/\svalidate\(\*arg.*?\)\s+# \(ActiveModel::Validations::ClassMethods\)/) + expect(out).to match(/\svalidate\(\*args, &block\)\s+#= Gem::Version.new('3.0.0') expect(out).to match(/\svalidate\(\*arg.*?\)\s+# \(ActiveModel::Validations::ClassMethods\)/) elsif (Gem::Version.new('2.6.7')..Gem::Version.new('2.7.1')).cover? Gem::Version.new(RUBY_VERSION) diff --git a/spec/formats_spec.rb b/spec/formats_spec.rb index df2b876..6d69d42 100644 --- a/spec/formats_spec.rb +++ b/spec/formats_spec.rb @@ -691,16 +691,16 @@ class My < Hash; end class My < File; end my = begin - File.new('/dev/null') + File.new(File::NULL) rescue StandardError - File.new('nul') + File.new(File::NULL) end expect(my.ai(plain: true)).to eq("#{my.inspect}\n" + `ls -alF #{my.path}`.chop) end it 'inherited from File should be displayed as File', :mswin do class My < File; end - my = My.new('nul') # it's /dev/null in Windows + my = My.new(File::NULL) # it's /dev/null in Windows expect(my.ai(plain: true)).to eq("#{my.inspect}\n" + AmazingPrint::Formatters::GetChildItem.new(my.path).to_s) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5167f72..4c034ab 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,7 +23,7 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each do |file| +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |file| require file end