Skip to content

Commit

Permalink
Upgrade to ActiveRecord 7.1 + Ruby 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
donv committed Apr 28, 2024
1 parent cdb2d0e commit 315fe22
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 138 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
ruby-version: '3.3'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Rubocop
run: bundle exec rubocop --auto-correct-all
Test:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
services:
postgres:
image: postgres
Expand All @@ -37,15 +37,15 @@ jobs:
fail-fast: false
matrix:
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
ruby: [ 3.1, '3.0', 2.7, 2.6, jruby, truffleruby ]
gemfile: [ ar70, ar61 ]
ruby: [ 3.3, 3.2, 3.1, jruby, truffleruby ]
gemfile: [ ar71, ar70 ]
adapter: [ postgresql, sqlite3 ]
exclude:
- ruby: jruby
adapter: sqlite3
- ruby: truffleruby
env:
ADAPTER: ${{ matrix.adapter }}
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/gems_${{ matrix.gemfile }}.rb
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Rails:

Security/Eval:
Exclude:
- 'gemfiles/*.gemfile'
- 'gemfiles/gems_*.rb'

Style/Documentation:
Enabled: false
Expand Down
46 changes: 20 additions & 26 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-11-25 11:12:32 UTC using RuboCop version 1.23.0.
# on 2024-04-28 21:09:41 UTC using RuboCop version 1.63.4.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -17,79 +17,73 @@ Lint/DuplicateBranch:
Exclude:
- 'lib/time_of_day.rb'

# Offense count: 3
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
# Offense count: 4
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 31

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# IgnoredMethods: refine
Metrics/BlockLength:
Max: 28
Max: 32

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 188
Max: 189

# Offense count: 1
# Configuration parameters: IgnoredMethods.
# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 10

# Offense count: 3
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 13

# Offense count: 1
# Configuration parameters: IgnoredMethods.
# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 11

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowToTime.
# SupportedStyles: strict, flexible
Rails/Date:
Exclude:
- 'lib/time_of_day.rb'

# Offense count: 1
# Cop supports --auto-correct.
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/WhereEquals:
Exclude:
- 'test/time_of_day_test.rb'

# Offense count: 1
# Cop supports --auto-correct.
# This cop supports safe autocorrection (--autocorrect).
Rails/WhereNot:
Exclude:
- 'test/time_of_day_test.rb'

# Offense count: 2
# Cop supports --auto-correct.
Security/YAMLLoad:
# Offense count: 1
Security/CompoundHash:
Exclude:
- 'test/test_helper.rb'
- 'test/time_of_day_test.rb'
- 'lib/time_of_day.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowModifiersOnSymbols.
# SupportedStyles: inline, group
Style/AccessModifierDeclarations:
EnforcedStyle: inline

# Offense count: 3
# Cop supports --auto-correct.
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: separated, grouped
Style/AccessorGrouping:
Exclude:
- 'lib/time_of_day.rb'

# Offense count: 1
# Cop supports --auto-correct.
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Expand All @@ -104,7 +98,7 @@ Style/OptionalBooleanParameter:
- 'lib/time_of_day.rb'

# Offense count: 5
# Cop supports --auto-correct.
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
Expand Down
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in activerecord-time.gemspec
gemspec

eval File.read("#{__dir__}/gemfiles/common.gemfile") # rubocop:disable Security/Eval

gem 'activerecord', ENV['AR_VERSION'] if ENV['AR_VERSION']
9 changes: 1 addition & 8 deletions activerecord-time.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
gem.summary = 'A handler for storing TimeOfDay objects in ActiveRecord objects as sql time values.'
gem.homepage = 'https://github.com/donv/activerecord-time'
gem.license = 'MIT'
gem.required_ruby_version = '>= 2.6'
gem.required_ruby_version = '>= 3.1'

gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
Expand All @@ -25,13 +25,6 @@ Gem::Specification.new do |gem|

gem.add_runtime_dependency 'activerecord', '~>7.0'

if defined? JRUBY_VERSION
gem.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
gem.add_development_dependency 'activerecord-jdbcsqlite3-adapter'
else
gem.add_development_dependency 'pg'
gem.add_development_dependency 'sqlite3'
end
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rubocop'
gem.add_development_dependency 'rubocop-performance'
Expand Down
3 changes: 0 additions & 3 deletions gemfiles/ar61.gemfile

This file was deleted.

3 changes: 0 additions & 3 deletions gemfiles/ar70.gemfile

This file was deleted.

26 changes: 1 addition & 25 deletions gemfiles/common.gemfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
source 'https://rubygems.org'

unless defined?(SKIP_JRUBY)
platform :jruby do
if defined?(RAILS_5)
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
"https://github.com/#{repo_name}.git"
end
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter'
gem 'activerecord-jdbcderby-adapter', github: 'jruby/activerecord-jdbc-adapter'
gem 'activerecord-jdbcpostgresql-adapter', github: 'jruby/activerecord-jdbc-adapter'
gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter'
gem 'jdbc-postgres', github: 'jruby/activerecord-jdbc-adapter'
gem 'jdbc-sqlite3', github: 'jruby/activerecord-jdbc-adapter'
else
# rubocop: disable Bundler/DuplicatedGem
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcderby-adapter'
gem 'activerecord-jdbcpostgresql-adapter'
gem 'activerecord-jdbcsqlite3-adapter'
# rubocop: enable Bundler/DuplicatedGem
end
end
end

platform :ruby do
gem 'pg'
gem 'sqlite3'
gem 'sqlite3', '<2'
end

gem 'minitest-reporters'
Expand Down
12 changes: 12 additions & 0 deletions gemfiles/gems_ar70.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

eval File.read("#{File.dirname __FILE__}/common.gemfile")

platform :jruby do
# gem 'activerecord-jdbc-adapter'
# gem 'activerecord-jdbcderby-adapter'
gem 'activerecord-jdbcpostgresql-adapter'
gem 'activerecord-jdbcsqlite3-adapter'
end

gem 'activerecord', '~>7.0.0'
18 changes: 18 additions & 0 deletions gemfiles/gems_ar71.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

eval File.read("#{File.dirname __FILE__}/common.gemfile")

platform :jruby do
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/')
"https://github.com/#{repo_name}.git"
end
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter'
# gem 'activerecord-jdbcderby-adapter', github: 'jruby/activerecord-jdbc-adapter'
gem 'activerecord-jdbcpostgresql-adapter', github: 'jruby/activerecord-jdbc-adapter'
gem 'activerecord-jdbcsqlite3-adapter', github: 'jruby/activerecord-jdbc-adapter'
gem 'jdbc-postgres', github: 'jruby/activerecord-jdbc-adapter'
gem 'jdbc-sqlite3', github: 'jruby/activerecord-jdbc-adapter'
end

gem 'activerecord', '~>7.1.0'
2 changes: 1 addition & 1 deletion lib/activerecord-time/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Activerecord
module Time
VERSION = '0.21.0'
VERSION = '0.22.0'
end
end
12 changes: 10 additions & 2 deletions lib/time_of_day.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def on(date)
Time.local(date.year, date.month, date.day, hour, minute, second) # rubocop: disable Rails/TimeZone
end

def change(*)
self
end

def year
2000
end

def +(other)
raise "Illegal argument: #{other.inspect}" unless other.is_a? Numeric

Expand All @@ -89,7 +97,7 @@ def -(other)
t2 = Time.local(0, 1, 1, other.hour, other.minute, other.second) # rubocop: disable Rails/TimeZone
(t1 - t2).seconds
when Numeric
self.+(-other)
self + -other
else
raise "Illegal argument: #{other.inspect}"
end
Expand Down Expand Up @@ -133,7 +141,7 @@ def to_s(with_seconds = true)
rescue
"#{@hour.inspect}:#{@minute.inspect}:#{@second.inspect}"
end
alias_method :to_fs, :to_s
alias to_fs to_s

def inspect
"#<#{self.class} hour=#{@hour}, minute=#{@minute}, second=#{@second}>"
Expand Down
1 change: 1 addition & 0 deletions lib/time_of_day/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def time_of_day
end
end

require 'date'
class DateTime
def time_of_day
TimeOfDay.new(hour, min, sec)
Expand Down
Loading

0 comments on commit 315fe22

Please sign in to comment.