polymorphic_integer_type 3.0.0 → 3.2.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: 96fa454bca5e242711a9cc17183c3dbfe7b8c9303bd0bbe1cd246d030761639d
4
- data.tar.gz: 536c3c02769ef0e020e300225e9e1cf453235d5341adc6f98cd973e1d7ea79d1
3
+ metadata.gz: e0a0c496105cf4f71bbb7d8e37f4b7d5464a155c6d69adc32860a42f57b54ce2
4
+ data.tar.gz: 6b91ce4961f8ff169c8a106bc258d25ff8f59aff0c59a97ed7488c9d708851bd
5
5
  SHA512:
6
- metadata.gz: dae28edc37bb45b1852a9d1f60347e74496d2ba371645514654ae9807a680de40d5487779b219a0fef3cad4ce220b2f0444e51c9907dbd6269653d2082eff1bf
7
- data.tar.gz: 32e6df91034dd5423d8c3787512246e570a1cec2d5d85bdfee2eed2d1932640562dc9ef08881aa6fe09edb1d218597613833ac56389f3807327a28cef7e517db
6
+ metadata.gz: 224efc3b41dc88ba440de3a87398a6422e817cc6adcedb216145d9fdfe004c9d3c5da733f81e547d27481dae3806290173dd4db65d4b72759084d0c4132a48d0
7
+ data.tar.gz: 91168a3fa7ed06b8de0c51b15d5199a66ede9e0b3265a7ea23861a796219f2948e9eef18b51c8c349fe23706ebfb9c9131fbec181a175c703c6d701061205a84
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ test/version_tmp
19
19
  tmp
20
20
  .byebug_history
21
21
  polymorphic_integer_type_test
22
+ gemfiles/*.lock
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec path: ".."
6
+
7
+ gem "activerecord", github: "rails/rails", branch: "6-1-stable"
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec path: ".."
6
+
7
+ gem "activerecord", github: "rails/rails", branch: "7-0-stable"
@@ -10,7 +10,12 @@ module PolymorphicIntegerType
10
10
  # end
11
11
 
12
12
  def type_to_ids_mapping
13
- association = @associated_table.send(:association)
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
18
+
14
19
  name = association.name
15
20
  default_hash = Hash.new { |hsh, key| hsh[key] = [] }
16
21
  values.each_with_object(default_hash) do |value, hash|
@@ -24,7 +29,7 @@ module PolymorphicIntegerType
24
29
 
25
30
  hash[key] << convert_to_id(value)
26
31
  else
27
- hash[klass.polymorphic_name] << convert_to_id(value)
32
+ hash[klass(value)&.polymorphic_name] << convert_to_id(value)
28
33
  end
29
34
  end
30
35
  end
@@ -1,10 +1,17 @@
1
1
  module ActiveRecord
2
2
  module Associations
3
3
  class BelongsToPolymorphicAssociation < BelongsToAssociation
4
- private def replace_keys(record)
5
- super
6
- unless record.nil?
7
- owner[reflection.foreign_type] = record.class.base_class
4
+ private
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?
8
15
  end
9
16
  end
10
17
  end
@@ -87,7 +87,7 @@ module PolymorphicIntegerType
87
87
  end
88
88
 
89
89
  remove_type_and_establish_mapping(name, options, scope)
90
- super(name, options.delete(:scope), options, &extension)
90
+ super(name, options.delete(:scope), **options, &extension)
91
91
  end
92
92
 
93
93
  def has_one(name, scope = nil, **options)
@@ -97,7 +97,7 @@ module PolymorphicIntegerType
97
97
  end
98
98
 
99
99
  remove_type_and_establish_mapping(name, options, scope)
100
- super(name, options.delete(:scope), options)
100
+ super(name, options.delete(:scope), **options)
101
101
  end
102
102
 
103
103
 
@@ -1,3 +1,3 @@
1
1
  module PolymorphicIntegerType
2
- VERSION = "3.0.0"
2
+ VERSION = "3.2.0"
3
3
  end
@@ -13,12 +13,12 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files -- . ':!.github/'`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activerecord", "< 6.1"
21
+ spec.add_dependency "activerecord", "< 7.1"
22
22
  spec.add_development_dependency "bundler"
23
23
  spec.add_development_dependency "rake"
24
24
  spec.add_development_dependency "rspec"
data/spec/spec_helper.rb CHANGED
@@ -17,14 +17,21 @@ require 'pry'
17
17
  RSpec.configure do |config|
18
18
  config.before(:suite) do
19
19
  database_config = YAML.load(File.open("#{File.dirname(__FILE__)}/support/database.yml"))
20
+ migrations_path = "#{File.dirname(__FILE__)}/support/migrations"
21
+ active_record_version = Gem::Version.new(ActiveRecord::VERSION::STRING)
22
+
20
23
  ActiveRecord::Base.establish_connection(database_config)
21
24
 
22
- if Gem::Version.new(ActiveRecord::VERSION::STRING) == Gem::Version.new("5.2.0")
23
- ActiveRecord::MigrationContext.new("#{File.dirname(__FILE__)}/support/migrations").migrate
25
+ if active_record_version < Gem::Version.new("5.2")
26
+ ActiveRecord::Migrator.migrate(migrations_path)
27
+ end
28
+
29
+ if active_record_version >= Gem::Version.new("5.2") && active_record_version < Gem::Version.new("6.0")
30
+ ActiveRecord::MigrationContext.new(migrations_path).migrate
24
31
  end
25
32
 
26
- if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("6.0")
27
- ActiveRecord::MigrationContext.new("#{File.dirname(__FILE__)}/support/migrations", ActiveRecord::SchemaMigration).migrate
33
+ if active_record_version >= Gem::Version.new("6.0")
34
+ ActiveRecord::MigrationContext.new(migrations_path, ActiveRecord::SchemaMigration).migrate
28
35
  end
29
36
  end
30
37
 
@@ -1,4 +1,4 @@
1
- class CreateLinkTable < ActiveRecord::Migration[5.2]
1
+ class CreateLinkTable < ActiveRecord::Migration[5.0]
2
2
 
3
3
  def up
4
4
  create_table :links do |t|
@@ -1,4 +1,4 @@
1
- class CreateAnimalTable < ActiveRecord::Migration[5.2]
1
+ class CreateAnimalTable < ActiveRecord::Migration[5.0]
2
2
 
3
3
  def up
4
4
  create_table :animals do |t|
@@ -1,4 +1,4 @@
1
- class CreatePersonTable < ActiveRecord::Migration[5.2]
1
+ class CreatePersonTable < ActiveRecord::Migration[5.0]
2
2
 
3
3
  def up
4
4
  create_table :people do |t|
@@ -1,4 +1,4 @@
1
- class CreateFoodTable < ActiveRecord::Migration[5.2]
1
+ class CreateFoodTable < ActiveRecord::Migration[5.0]
2
2
 
3
3
  def up
4
4
  create_table :foods do |t|
@@ -1,4 +1,4 @@
1
- class CreateDrinkTable < ActiveRecord::Migration[5.2]
1
+ class CreateDrinkTable < ActiveRecord::Migration[5.0]
2
2
 
3
3
  def up
4
4
  create_table :drinks do |t|
@@ -1,4 +1,4 @@
1
- class CreatePlantTable < ActiveRecord::Migration[5.2]
1
+ class CreatePlantTable < ActiveRecord::Migration[5.0]
2
2
 
3
3
  def up
4
4
  create_table :plants do |t|
@@ -1,4 +1,4 @@
1
- class CreateActivityTable < ActiveRecord::Migration[5.2]
1
+ class CreateActivityTable < ActiveRecord::Migration[5.0]
2
2
 
3
3
  def up
4
4
  create_table :activities do |t|
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.0.0
4
+ version: 3.2.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: 2021-05-20 00:00:00.000000000 Z
11
+ date: 2023-06-09 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: '6.1'
19
+ version: '7.1'
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: '6.1'
26
+ version: '7.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -109,13 +109,11 @@ files:
109
109
  - Rakefile
110
110
  - bin/setup
111
111
  - gemfiles/Gemfile.rails-5.0-stable
112
- - gemfiles/Gemfile.rails-5.0-stable.lock
113
112
  - gemfiles/Gemfile.rails-5.1-stable
114
- - gemfiles/Gemfile.rails-5.1-stable.lock
115
113
  - gemfiles/Gemfile.rails-5.2-stable
116
- - gemfiles/Gemfile.rails-5.2-stable.lock
117
- - gemfiles/Gemfile.rails-6-0-stable
118
- - gemfiles/Gemfile.rails-6-0-stable.lock
114
+ - gemfiles/Gemfile.rails-6.0-stable
115
+ - gemfiles/Gemfile.rails-6.1-stable
116
+ - gemfiles/Gemfile.rails-7.0-stable
119
117
  - lib/polymorphic_integer_type.rb
120
118
  - lib/polymorphic_integer_type/activerecord_5_0_0/association_query_handler_extension.rb
121
119
  - lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb
@@ -149,7 +147,7 @@ homepage: ''
149
147
  licenses:
150
148
  - MIT
151
149
  metadata: {}
152
- post_install_message:
150
+ post_install_message:
153
151
  rdoc_options: []
154
152
  require_paths:
155
153
  - lib
@@ -164,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
162
  - !ruby/object:Gem::Version
165
163
  version: '0'
166
164
  requirements: []
167
- rubygems_version: 3.1.6
168
- signing_key:
165
+ rubygems_version: 3.4.10
166
+ signing_key:
169
167
  specification_version: 4
170
168
  summary: Use integers rather than strings for the _type field
171
169
  test_files:
@@ -1,74 +0,0 @@
1
- GIT
2
- remote: https://github.com/rails/rails.git
3
- revision: ac6aa32f7cf66264ba87eabed7c042bb60bcf3a2
4
- branch: 5-0-stable
5
- specs:
6
- activemodel (5.0.7.2)
7
- activesupport (= 5.0.7.2)
8
- activerecord (5.0.7.2)
9
- activemodel (= 5.0.7.2)
10
- activesupport (= 5.0.7.2)
11
- arel (~> 7.0)
12
- activesupport (5.0.7.2)
13
- concurrent-ruby (~> 1.0, >= 1.0.2)
14
- i18n (>= 0.7, < 2)
15
- minitest (~> 5.1)
16
- tzinfo (~> 1.1)
17
-
18
- PATH
19
- remote: ..
20
- specs:
21
- polymorphic_integer_type (3.0.0)
22
- activerecord (< 6.1)
23
-
24
- GEM
25
- remote: https://rubygems.org/
26
- specs:
27
- arel (7.1.4)
28
- byebug (11.1.3)
29
- coderay (1.1.3)
30
- concurrent-ruby (1.1.8)
31
- diff-lcs (1.4.4)
32
- i18n (1.8.10)
33
- concurrent-ruby (~> 1.0)
34
- method_source (1.0.0)
35
- minitest (5.14.4)
36
- pry (0.13.1)
37
- coderay (~> 1.1)
38
- method_source (~> 1.0)
39
- pry-byebug (3.9.0)
40
- byebug (~> 11.0)
41
- pry (~> 0.13.0)
42
- rake (13.0.3)
43
- rspec (3.10.0)
44
- rspec-core (~> 3.10.0)
45
- rspec-expectations (~> 3.10.0)
46
- rspec-mocks (~> 3.10.0)
47
- rspec-core (3.10.1)
48
- rspec-support (~> 3.10.0)
49
- rspec-expectations (3.10.1)
50
- diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.10.0)
52
- rspec-mocks (3.10.2)
53
- diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.10.0)
55
- rspec-support (3.10.2)
56
- sqlite3 (1.3.13)
57
- thread_safe (0.3.6)
58
- tzinfo (1.2.9)
59
- thread_safe (~> 0.1)
60
-
61
- PLATFORMS
62
- ruby
63
-
64
- DEPENDENCIES
65
- activerecord!
66
- bundler
67
- polymorphic_integer_type!
68
- pry-byebug
69
- rake
70
- rspec
71
- sqlite3 (~> 1.3.6)
72
-
73
- BUNDLED WITH
74
- 2.1.4
@@ -1,74 +0,0 @@
1
- GIT
2
- remote: https://github.com/rails/rails.git
3
- revision: 663206d20aec374a28a24bb43bc7b1233042ed9b
4
- branch: 5-1-stable
5
- specs:
6
- activemodel (5.1.7)
7
- activesupport (= 5.1.7)
8
- activerecord (5.1.7)
9
- activemodel (= 5.1.7)
10
- activesupport (= 5.1.7)
11
- arel (~> 8.0)
12
- activesupport (5.1.7)
13
- concurrent-ruby (~> 1.0, >= 1.0.2)
14
- i18n (>= 0.7, < 2)
15
- minitest (~> 5.1)
16
- tzinfo (~> 1.1)
17
-
18
- PATH
19
- remote: ..
20
- specs:
21
- polymorphic_integer_type (3.0.0)
22
- activerecord (< 6.1)
23
-
24
- GEM
25
- remote: https://rubygems.org/
26
- specs:
27
- arel (8.0.0)
28
- byebug (11.1.3)
29
- coderay (1.1.3)
30
- concurrent-ruby (1.1.8)
31
- diff-lcs (1.4.4)
32
- i18n (1.8.10)
33
- concurrent-ruby (~> 1.0)
34
- method_source (1.0.0)
35
- minitest (5.14.4)
36
- pry (0.13.1)
37
- coderay (~> 1.1)
38
- method_source (~> 1.0)
39
- pry-byebug (3.9.0)
40
- byebug (~> 11.0)
41
- pry (~> 0.13.0)
42
- rake (13.0.3)
43
- rspec (3.10.0)
44
- rspec-core (~> 3.10.0)
45
- rspec-expectations (~> 3.10.0)
46
- rspec-mocks (~> 3.10.0)
47
- rspec-core (3.10.1)
48
- rspec-support (~> 3.10.0)
49
- rspec-expectations (3.10.1)
50
- diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.10.0)
52
- rspec-mocks (3.10.2)
53
- diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.10.0)
55
- rspec-support (3.10.2)
56
- sqlite3 (1.4.2)
57
- thread_safe (0.3.6)
58
- tzinfo (1.2.9)
59
- thread_safe (~> 0.1)
60
-
61
- PLATFORMS
62
- ruby
63
-
64
- DEPENDENCIES
65
- activerecord!
66
- bundler
67
- polymorphic_integer_type!
68
- pry-byebug
69
- rake
70
- rspec
71
- sqlite3
72
-
73
- BUNDLED WITH
74
- 2.1.4
@@ -1,74 +0,0 @@
1
- GIT
2
- remote: https://github.com/rails/rails.git
3
- revision: 48661542a2607d55f436438fe21001d262e61fec
4
- branch: 5-2-stable
5
- specs:
6
- activemodel (5.2.6)
7
- activesupport (= 5.2.6)
8
- activerecord (5.2.6)
9
- activemodel (= 5.2.6)
10
- activesupport (= 5.2.6)
11
- arel (>= 9.0)
12
- activesupport (5.2.6)
13
- concurrent-ruby (~> 1.0, >= 1.0.2)
14
- i18n (>= 0.7, < 2)
15
- minitest (~> 5.1)
16
- tzinfo (~> 1.1)
17
-
18
- PATH
19
- remote: ..
20
- specs:
21
- polymorphic_integer_type (3.0.0)
22
- activerecord (< 6.1)
23
-
24
- GEM
25
- remote: https://rubygems.org/
26
- specs:
27
- arel (9.0.0)
28
- byebug (11.1.3)
29
- coderay (1.1.3)
30
- concurrent-ruby (1.1.8)
31
- diff-lcs (1.4.4)
32
- i18n (1.8.10)
33
- concurrent-ruby (~> 1.0)
34
- method_source (1.0.0)
35
- minitest (5.14.4)
36
- pry (0.13.1)
37
- coderay (~> 1.1)
38
- method_source (~> 1.0)
39
- pry-byebug (3.9.0)
40
- byebug (~> 11.0)
41
- pry (~> 0.13.0)
42
- rake (13.0.3)
43
- rspec (3.10.0)
44
- rspec-core (~> 3.10.0)
45
- rspec-expectations (~> 3.10.0)
46
- rspec-mocks (~> 3.10.0)
47
- rspec-core (3.10.1)
48
- rspec-support (~> 3.10.0)
49
- rspec-expectations (3.10.1)
50
- diff-lcs (>= 1.2.0, < 2.0)
51
- rspec-support (~> 3.10.0)
52
- rspec-mocks (3.10.2)
53
- diff-lcs (>= 1.2.0, < 2.0)
54
- rspec-support (~> 3.10.0)
55
- rspec-support (3.10.2)
56
- sqlite3 (1.4.2)
57
- thread_safe (0.3.6)
58
- tzinfo (1.2.9)
59
- thread_safe (~> 0.1)
60
-
61
- PLATFORMS
62
- ruby
63
-
64
- DEPENDENCIES
65
- activerecord!
66
- bundler
67
- polymorphic_integer_type!
68
- pry-byebug
69
- rake
70
- rspec
71
- sqlite3
72
-
73
- BUNDLED WITH
74
- 2.1.4
@@ -1,74 +0,0 @@
1
- GIT
2
- remote: https://github.com/rails/rails.git
3
- revision: ef97441036e0ebbe1aa2108d59c408707f998ffd
4
- branch: 6-0-stable
5
- specs:
6
- activemodel (6.0.3.7)
7
- activesupport (= 6.0.3.7)
8
- activerecord (6.0.3.7)
9
- activemodel (= 6.0.3.7)
10
- activesupport (= 6.0.3.7)
11
- activesupport (6.0.3.7)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- zeitwerk (~> 2.2, >= 2.2.2)
17
-
18
- PATH
19
- remote: ..
20
- specs:
21
- polymorphic_integer_type (3.0.0)
22
- activerecord (< 6.1)
23
-
24
- GEM
25
- remote: https://rubygems.org/
26
- specs:
27
- byebug (11.1.3)
28
- coderay (1.1.3)
29
- concurrent-ruby (1.1.8)
30
- diff-lcs (1.4.4)
31
- i18n (1.8.10)
32
- concurrent-ruby (~> 1.0)
33
- method_source (1.0.0)
34
- minitest (5.14.4)
35
- pry (0.13.1)
36
- coderay (~> 1.1)
37
- method_source (~> 1.0)
38
- pry-byebug (3.9.0)
39
- byebug (~> 11.0)
40
- pry (~> 0.13.0)
41
- rake (13.0.3)
42
- rspec (3.10.0)
43
- rspec-core (~> 3.10.0)
44
- rspec-expectations (~> 3.10.0)
45
- rspec-mocks (~> 3.10.0)
46
- rspec-core (3.10.1)
47
- rspec-support (~> 3.10.0)
48
- rspec-expectations (3.10.1)
49
- diff-lcs (>= 1.2.0, < 2.0)
50
- rspec-support (~> 3.10.0)
51
- rspec-mocks (3.10.2)
52
- diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.10.0)
54
- rspec-support (3.10.2)
55
- sqlite3 (1.4.2)
56
- thread_safe (0.3.6)
57
- tzinfo (1.2.9)
58
- thread_safe (~> 0.1)
59
- zeitwerk (2.4.2)
60
-
61
- PLATFORMS
62
- ruby
63
-
64
- DEPENDENCIES
65
- activerecord!
66
- bundler
67
- polymorphic_integer_type!
68
- pry-byebug
69
- rake
70
- rspec
71
- sqlite3
72
-
73
- BUNDLED WITH
74
- 2.1.4