polymorphic_integer_type 3.2.2 → 3.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
2
  SHA256:
3
- metadata.gz: cfa2f9c68364a27168180b5dfeaae71b6ea2a9e74c313a8f42658b6e3a562dcd
4
- data.tar.gz: b4f0b2225be4e6d8270f1e4d1755a15d791aec80a3f20afd3cd2c6d9f4923603
3
+ metadata.gz: 549bf216afd3997c36413d2b6723e0cbc9256a7a6efa6fed0ce1befdb1400d10
4
+ data.tar.gz: 80f07a091c228c80ba6f0a010a86c4a499a4aedeb96deab847a906a7b994d0f6
5
5
  SHA512:
6
- metadata.gz: 12fa770fcb992eb05270b971a8f1ff88d881318d09bccc9f3e7d139e01396054873a68f1083238db0af4d7dc32bf3a715a51d848df2d9432e060580a6b524cf8
7
- data.tar.gz: ca0d6e461f1543b2f47476d53e679d24de1420e60acaa8c51119f1bfa05ac962f5ac189912d9a7ae12e63f9568af91e6e0550dbc448efc3b2e75c6f655a8e0c5
6
+ metadata.gz: a012c19a75500b92faefd0b559a34a357de645570804ca604ab1e5964fbc2d7f09031395bbf679b825d02798face13870f4a0b1e8f752442ba517c945767e91b
7
+ data.tar.gz: 3285ff0990650aec63cf0a3662b738969783e9cc868468a59272b675385ef396c0097c8996b237050c5ac17a604c6fa651b9c5a735a01c186b9d5a9ad63430bb
data/.gitignore CHANGED
@@ -21,3 +21,6 @@ tmp
21
21
  polymorphic_integer_type_test
22
22
  gemfiles/*.lock
23
23
  .idea/
24
+ .ruby-version
25
+ mysql
26
+ polymorphic_integer_type_test-*
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### Changed
1
+ # Changelog
2
2
 
3
3
  ## v3.2.1 (2023-12-14)
4
4
 
@@ -16,4 +16,21 @@
16
16
 
17
17
  - Fixed polymorphic_foreign_association_extension.rb to be compatible with other reflection than `has_many` and `has_one`.
18
18
 
19
- ### Changed
19
+ ## v3.3.0 (2024-10-29)
20
+
21
+ ### Changed
22
+
23
+ - Upgrade rails support version to be compatible with 7.2
24
+
25
+ ### Removed
26
+
27
+ - Remove unsupported rails versions(5.0, 5.2, 6.0) and ruby version(2.7)
28
+
29
+ ## v3.4.0 (2024-XX-XX)
30
+
31
+ ### Added
32
+
33
+ - Add Rails 8.0 compatibility (requires Ruby 3.2+)
34
+
35
+ ### Removed
36
+ - Remove unsupported rails versions 6.x
data/README.md CHANGED
@@ -138,16 +138,23 @@ Lastly, you will need to be careful of any place where you are doing raw SQL que
138
138
 
139
139
  ## Setup
140
140
 
141
- You'll need to have git, Ruby, and MySQL. Then get up and running with a few commands:
141
+ You'll need to have git and Ruby. Then get up and running with a few commands:
142
142
 
143
143
  ```bash
144
144
  $ git clone ...
145
145
  $ bundle install
146
146
  $ vim spec/support/database.yml # Update username and password
147
- $ bin/setup
147
+ $ bin/setup # Uses SQLite3 for testing (no additional setup required)
148
148
  $ bundle exec rspec
149
149
  ```
150
150
 
151
+ ## Database Compatibility
152
+
153
+ This gem works with any database supported by ActiveRecord (SQLite3, MySQL, PostgreSQL, etc.).
154
+ The gem extends ActiveRecord's polymorphic associations and doesn't use database-specific features.
155
+
156
+ Development and testing uses SQLite3 for simplicity.
157
+
151
158
  ## Contributing
152
159
 
153
160
  1. Fork it
data/Rakefile CHANGED
@@ -1,48 +1,52 @@
1
- require "bundler/gem_tasks"
2
- require "yaml"
3
- require "active_record"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'yaml'
5
+ require 'active_record'
4
6
 
5
7
  namespace :test do
6
8
  task :all do
7
- Dir.glob("./gemfiles/Gemfile*").each do |gemfile|
8
- next if gemfile.end_with?(".lock")
9
+ Dir.glob('./gemfiles/Gemfile*').each do |gemfile|
10
+ next if gemfile.end_with?('.lock')
11
+
9
12
  puts "Running specs for #{Pathname.new(gemfile).basename}"
10
13
  system("BUNDLE_GEMFILE=#{gemfile} bundle install > /dev/null && BUNDLE_GEMFILE=#{gemfile} bundle exec rspec")
11
- puts ""
14
+ puts ''
12
15
  end
13
16
  end
14
17
  end
15
18
 
16
19
  namespace :db do
17
- database_config = YAML.load(File.open("./spec/support/database.yml"))
18
- admin_database_config = database_config.merge(database: "mysql")
19
- migration_path = File.expand_path("./spec/support/migrations")
20
+ database_config = YAML.load(File.open('./spec/support/database.yml'))
21
+ migration_path = File.expand_path('./spec/support/migrations')
20
22
 
21
- desc "Create the database"
23
+ desc 'Create the database'
22
24
  task :create do
23
- ActiveRecord::Base.establish_connection(admin_database_config)
24
- ActiveRecord::Base.connection.create_database(database_config.fetch(:database))
25
- puts "Database created."
25
+ # SQLite3 creates the database file automatically, just ensure directory exists
26
+ db_file = database_config.fetch(:database)
27
+ FileUtils.mkdir_p(File.dirname(db_file)) unless File.dirname(db_file) == '.'
28
+ puts 'Database ready (SQLite3).'
26
29
  end
27
30
 
28
- desc "Migrate the database"
31
+ desc 'Migrate the database'
29
32
  task :migrate do
30
33
  ActiveRecord::Base.establish_connection(database_config)
31
- ActiveRecord::Migrator.migrate(migration_path)
32
- Rake::Task["db:schema"].invoke
33
- puts "Database migrated."
34
+ ActiveRecord::MigrationContext.new(migration_path).migrate
35
+ Rake::Task['db:schema'].invoke
36
+ puts 'Database migrated.'
34
37
  end
35
38
 
36
- desc "Drop the database"
39
+ desc 'Drop the database'
37
40
  task :drop do
38
- ActiveRecord::Base.establish_connection(admin_database_config)
39
- ActiveRecord::Base.connection.drop_database(database_config.fetch(:database))
40
- puts "Database deleted."
41
+ # For SQLite3, just delete the file
42
+ db_file = database_config.fetch(:database)
43
+ File.delete(db_file) if File.exist?(db_file)
44
+ puts 'Database deleted.'
41
45
  end
42
46
 
43
- desc "Reset the database"
47
+ desc 'Reset the database'
44
48
  task reset: [:drop, :create, :migrate]
45
- desc 'Create a db/schema.rb file that is portable against any DB supported by AR'
49
+ desc 'Create a db/schema.rb file that is portable against any DB supported by AR'
46
50
 
47
51
  task :schema do
48
52
  # Noop to make ActiveRecord happy
@@ -5,3 +5,4 @@ source "https://rubygems.org"
5
5
  gemspec path: ".."
6
6
 
7
7
  gem "activerecord", github: "rails/rails", branch: "7-0-stable"
8
+ gem "sqlite3", "~> 1.4"
@@ -4,4 +4,4 @@ source "https://rubygems.org"
4
4
 
5
5
  gemspec path: ".."
6
6
 
7
- gem "activerecord", github: "rails/rails", branch: "6-1-stable"
7
+ gem "activerecord", github: "rails/rails", branch: "7-2-stable"
@@ -4,4 +4,4 @@ source "https://rubygems.org"
4
4
 
5
5
  gemspec path: ".."
6
6
 
7
- gem "activerecord", github: "rails/rails", branch: "5-1-stable"
7
+ gem "activerecord", github: "rails/rails", branch: "8-0-stable"
@@ -10,11 +10,7 @@ module PolymorphicIntegerType
10
10
  # end
11
11
 
12
12
  def type_to_ids_mapping
13
- if ACTIVE_RECORD_VERSION < Gem::Version.new("6.1")
14
- association = @associated_table.send(:association)
15
- else
16
- association = @associated_table.send(:reflection)
17
- end
13
+ association = @associated_table.send(:reflection)
18
14
 
19
15
  name = association.name
20
16
  default_hash = Hash.new { |hsh, key| hsh[key] = [] }
@@ -3,16 +3,9 @@ module ActiveRecord
3
3
  class BelongsToPolymorphicAssociation < BelongsToAssociation
4
4
  private
5
5
 
6
- if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("6.1")
7
- def replace_keys(record)
8
- super
9
- owner[reflection.foreign_type] = record.class.base_class unless record.nil?
10
- end
11
- elsif
12
- def replace_keys(record, force: false)
13
- super
14
- owner[reflection.foreign_type] = record.class.base_class unless record.nil?
15
- end
6
+ def replace_keys(record, force: false)
7
+ super
8
+ owner[reflection.foreign_type] = record.class.base_class unless record.nil?
16
9
  end
17
10
  end
18
11
  end
@@ -118,12 +118,7 @@ module PolymorphicIntegerType
118
118
  if is_polymorphic_integer
119
119
  reflection.foreign_integer_type = foreign_integer_type
120
120
  reflection.integer_type = integer_type
121
-
122
- if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("6.1")
123
- ActiveRecord::Associations::Association.prepend(PolymorphicIntegerType::PolymorphicForeignAssociationExtension)
124
- else
125
- ActiveRecord::Associations::ForeignAssociation.prepend(PolymorphicIntegerType::PolymorphicForeignAssociationExtension)
126
- end
121
+ ActiveRecord::Associations::ForeignAssociation.prepend(PolymorphicIntegerType::PolymorphicForeignAssociationExtension)
127
122
  end
128
123
  end
129
124
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module PolymorphicIntegerType
2
- VERSION = "3.2.2"
4
+ VERSION = '3.4.0'
3
5
  end
@@ -1,27 +1,30 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'polymorphic_integer_type/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "polymorphic_integer_type"
8
+ spec.name = 'polymorphic_integer_type'
8
9
  spec.version = PolymorphicIntegerType::VERSION
9
- spec.authors = ["Kyle d'Oliveira"]
10
- spec.email = ["kyle@goclio.com"]
11
- spec.description = %q{Allows the *_type field in the DB to be an integer rather than a string}
12
- spec.summary = %q{Use integers rather than strings for the _type field}
13
- spec.homepage = ""
14
- spec.license = "MIT"
10
+ spec.authors = ['Kyle d\'Oliveira']
11
+ spec.email = ['kyle@goclio.com']
12
+ spec.description = 'Allows the *_type field in the DB to be an integer rather than a string'
13
+ spec.summary = 'Use integers rather than strings for the _type field'
14
+ spec.homepage = ''
15
+ spec.license = 'MIT'
16
+
17
+ spec.required_ruby_version = '>= 3.0'
15
18
 
16
19
  spec.files = `git ls-files -- . ':!.github/'`.split($/)
17
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
22
+ spec.require_paths = ['lib']
20
23
 
21
- spec.add_dependency "activerecord", "< 7.1"
22
- spec.add_development_dependency "bundler"
23
- spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec"
25
- spec.add_development_dependency "sqlite3"
26
- spec.add_development_dependency "pry-byebug"
24
+ spec.add_dependency 'activerecord', '< 9.0'
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'pry-byebug'
27
+ spec.add_development_dependency 'rake'
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'sqlite3'
27
30
  end
@@ -175,7 +175,7 @@ describe PolymorphicIntegerType do
175
175
  before { link }
176
176
 
177
177
  it "should have the proper source" do
178
- expect(source.source_links[0].source).to eql source
178
+ expect(source.reload.source_links[0].source).to eql source
179
179
  end
180
180
  end
181
181
  end
data/spec/spec_helper.rb CHANGED
@@ -20,21 +20,10 @@ RSpec.configure do |config|
20
20
  config.before(:suite) do
21
21
  database_config = YAML.load(File.open("#{File.dirname(__FILE__)}/support/database.yml"))
22
22
  migrations_path = "#{File.dirname(__FILE__)}/support/migrations"
23
- active_record_version = Gem::Version.new(ActiveRecord::VERSION::STRING)
24
23
 
25
24
  ActiveRecord::Base.establish_connection(database_config)
26
25
 
27
- if active_record_version < Gem::Version.new("5.2")
28
- ActiveRecord::Migrator.migrate(migrations_path)
29
- end
30
-
31
- if active_record_version >= Gem::Version.new("5.2") && active_record_version < Gem::Version.new("6.0")
32
- ActiveRecord::MigrationContext.new(migrations_path).migrate
33
- end
34
-
35
- if active_record_version >= Gem::Version.new("6.0")
36
- ActiveRecord::MigrationContext.new(migrations_path, ActiveRecord::SchemaMigration).migrate
37
- end
26
+ ActiveRecord::MigrationContext.new(migrations_path).migrate
38
27
  end
39
28
 
40
29
  config.around do |example|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polymorphic_integer_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.2
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle d'Oliveira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-21 00:00:00.000000000 Z
11
+ date: 2025-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: '7.1'
19
+ version: '9.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '7.1'
26
+ version: '9.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: pry-byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: sqlite3
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry-byebug
84
+ name: sqlite3
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -109,12 +109,9 @@ files:
109
109
  - README.md
110
110
  - Rakefile
111
111
  - bin/setup
112
- - gemfiles/Gemfile.rails-5.0-stable
113
- - gemfiles/Gemfile.rails-5.1-stable
114
- - gemfiles/Gemfile.rails-5.2-stable
115
- - gemfiles/Gemfile.rails-6.0-stable
116
- - gemfiles/Gemfile.rails-6.1-stable
117
112
  - gemfiles/Gemfile.rails-7.0-stable
113
+ - gemfiles/Gemfile.rails-7.2-stable
114
+ - gemfiles/Gemfile.rails-8.0-stable
118
115
  - lib/polymorphic_integer_type.rb
119
116
  - lib/polymorphic_integer_type/activerecord_5_0_0/association_query_handler_extension.rb
120
117
  - lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb
@@ -153,7 +150,7 @@ homepage: ''
153
150
  licenses:
154
151
  - MIT
155
152
  metadata: {}
156
- post_install_message:
153
+ post_install_message:
157
154
  rdoc_options: []
158
155
  require_paths:
159
156
  - lib
@@ -161,15 +158,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
158
  requirements:
162
159
  - - ">="
163
160
  - !ruby/object:Gem::Version
164
- version: '0'
161
+ version: '3.0'
165
162
  required_rubygems_version: !ruby/object:Gem::Requirement
166
163
  requirements:
167
164
  - - ">="
168
165
  - !ruby/object:Gem::Version
169
166
  version: '0'
170
167
  requirements: []
171
- rubygems_version: 3.4.10
172
- signing_key:
168
+ rubygems_version: 3.3.27
169
+ signing_key:
173
170
  specification_version: 4
174
171
  summary: Use integers rather than strings for the _type field
175
172
  test_files:
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gemspec path: ".."
6
-
7
- gem "activerecord", github: "rails/rails", branch: "5-0-stable"
8
- gem "sqlite3", "~> 1.3.6"
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gemspec path: ".."
6
-
7
- gem "activerecord", github: "rails/rails", branch: "5-2-stable"
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gemspec path: ".."
6
-
7
- gem "activerecord", github: "rails/rails", branch: "6-0-stable"