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 +4 -4
- data/.gitignore +3 -0
- data/CHANGELOG.md +19 -2
- data/README.md +9 -2
- data/Rakefile +27 -23
- data/gemfiles/Gemfile.rails-7.0-stable +1 -0
- data/gemfiles/{Gemfile.rails-6.1-stable → Gemfile.rails-7.2-stable} +1 -1
- data/gemfiles/{Gemfile.rails-5.1-stable → Gemfile.rails-8.0-stable} +1 -1
- data/lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb +1 -5
- data/lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb +3 -10
- data/lib/polymorphic_integer_type/extensions.rb +1 -6
- data/lib/polymorphic_integer_type/version.rb +3 -1
- data/polymorphic_integer_type.gemspec +19 -16
- data/spec/polymorphic_integer_type_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -12
- metadata +15 -18
- data/gemfiles/Gemfile.rails-5.0-stable +0 -8
- data/gemfiles/Gemfile.rails-5.2-stable +0 -7
- data/gemfiles/Gemfile.rails-6.0-stable +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 549bf216afd3997c36413d2b6723e0cbc9256a7a6efa6fed0ce1befdb1400d10
|
4
|
+
data.tar.gz: 80f07a091c228c80ba6f0a010a86c4a499a4aedeb96deab847a906a7b994d0f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a012c19a75500b92faefd0b559a34a357de645570804ca604ab1e5964fbc2d7f09031395bbf679b825d02798face13870f4a0b1e8f752442ba517c945767e91b
|
7
|
+
data.tar.gz: 3285ff0990650aec63cf0a3662b738969783e9cc868468a59272b675385ef396c0097c8996b237050c5ac17a604c6fa651b9c5a735a01c186b9d5a9ad63430bb
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
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
|
-
|
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
|
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
|
-
|
2
|
-
|
3
|
-
require
|
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(
|
8
|
-
next if gemfile.end_with?(
|
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(
|
18
|
-
|
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
|
23
|
+
desc 'Create the database'
|
22
24
|
task :create do
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
31
|
+
desc 'Migrate the database'
|
29
32
|
task :migrate do
|
30
33
|
ActiveRecord::Base.establish_connection(database_config)
|
31
|
-
ActiveRecord::
|
32
|
-
Rake::Task[
|
33
|
-
puts
|
34
|
+
ActiveRecord::MigrationContext.new(migration_path).migrate
|
35
|
+
Rake::Task['db:schema'].invoke
|
36
|
+
puts 'Database migrated.'
|
34
37
|
end
|
35
38
|
|
36
|
-
desc
|
39
|
+
desc 'Drop the database'
|
37
40
|
task :drop do
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
47
|
+
desc 'Reset the database'
|
44
48
|
task reset: [:drop, :create, :migrate]
|
45
|
-
|
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
|
@@ -10,11 +10,7 @@ module PolymorphicIntegerType
|
|
10
10
|
# end
|
11
11
|
|
12
12
|
def type_to_ids_mapping
|
13
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
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,27 +1,30 @@
|
|
1
|
-
#
|
2
|
-
|
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 =
|
8
|
+
spec.name = 'polymorphic_integer_type'
|
8
9
|
spec.version = PolymorphicIntegerType::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
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 = [
|
22
|
+
spec.require_paths = ['lib']
|
20
23
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
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
|
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
|
-
|
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.
|
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:
|
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: '
|
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: '
|
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:
|
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:
|
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:
|
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:
|
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.
|
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:
|