store_base_sti_class 2.0.1 → 3.0.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: d905b8e881303f37a959af003a8ae10b9a8c47d936a6adb9afc75bf149dbbd68
4
- data.tar.gz: 53baeb1bf2222de935343215b1bfa036d3cbd4c26ae6087ead371e0918e11754
3
+ metadata.gz: 6bfa35237d6d92294c821edbb70e75070df5109027f984e567ea4d372cdbb5b1
4
+ data.tar.gz: c99a988b260c44d272790ae8e0ac47a09d3d75f2b248f4dab4759b63b7cff3f3
5
5
  SHA512:
6
- metadata.gz: 285c2c32254eb69039e4cc5337065dcde7f1a99f65fdc6902e1027e6dbd380a36bd488ae87c0e5b2c718d463ce0f4a5fb82f1993246bab4f7ccee0ca2914c2ab
7
- data.tar.gz: 9be85dd36e7ed71a298d95dc434940e73a05de94d798d21cf46d9b805a683129272ee07688e684c056a46bc7ce9321e06a6f2ece71f2f4219eeab11f902ef1f9
6
+ metadata.gz: 6dccdf1b15ea2c0da67d06dcd9f5b2b81a8ab30e529658565de35cabe389998b54ad13b0b4e4732841f8b0c4a52c269899c742b86b0c1d2450be97f199110658
7
+ data.tar.gz: f8eb0a6a6dc3c677aabdbad59753413d8620b48b586e8c90143a0e232099bb56aca538d395f01b6424ca566151d1b63c9afa75f9e2b0178ef94cf70a352a19d6
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2019 AppFolio, inc.
1
+ Copyright (c) 2011-2022 AppFolio, Inc
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,3 +1,3 @@
1
1
  module StoreBaseSTIClass
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
@@ -1,16 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_record'
2
4
 
3
- if ActiveRecord::VERSION::STRING =~ /^4\.2/
4
- require 'store_base_sti_class_for_4_2'
5
- elsif ActiveRecord::VERSION::STRING =~ /^5\.0/
6
- require 'store_base_sti_class_for_5_0'
7
- elsif ActiveRecord::VERSION::STRING =~ /^5\.1/
8
- require 'store_base_sti_class_for_5_1'
9
- elsif ActiveRecord::VERSION::STRING =~ /^5\.2/
10
- require 'store_base_sti_class_for_5_2'
11
- elsif ActiveRecord::VERSION::STRING =~ /^6\.0/
12
- require 'store_base_sti_class_for_6_0'
13
- end
5
+ require "store_base_sti_class_for_#{ActiveRecord::VERSION::MAJOR}_#{ActiveRecord::VERSION::MINOR}"
14
6
 
15
7
  module StoreBaseSTIClass
16
8
  end
@@ -1,6 +1,6 @@
1
1
  require 'active_record/associations/join_dependency/join_part'
2
2
 
3
- if ActiveRecord::VERSION::STRING =~ /^5\.2/
3
+ if ActiveRecord::VERSION::STRING =~ /^6\.1/
4
4
  module ActiveRecord
5
5
 
6
6
  class Base
@@ -25,8 +25,12 @@ if ActiveRecord::VERSION::STRING =~ /^5\.2/
25
25
  scope = through_reflection.klass.unscoped
26
26
  options = reflection.options
27
27
 
28
- if options[:source_type]
28
+ values = reflection_scope.values
29
+ if annotations = values[:annotate]
30
+ scope.annotate!(*annotations)
31
+ end
29
32
 
33
+ if options[:source_type]
30
34
  # BEGIN PATCH
31
35
  # original:
32
36
  # scope.where! reflection.foreign_type => options[:source_type]
@@ -43,7 +47,6 @@ if ActiveRecord::VERSION::STRING =~ /^5\.2/
43
47
 
44
48
  elsif !reflection_scope.where_clause.empty?
45
49
  scope.where_clause = reflection_scope.where_clause
46
- values = reflection_scope.values
47
50
 
48
51
  if includes = values[:includes]
49
52
  scope.includes!(source_reflection.name => includes)
@@ -52,7 +55,7 @@ if ActiveRecord::VERSION::STRING =~ /^5\.2/
52
55
  end
53
56
 
54
57
  if values[:references] && !values[:references].empty?
55
- scope.references!(values[:references])
58
+ scope.references_values |= values[:references]
56
59
  else
57
60
  scope.references!(source_reflection.table_name)
58
61
  end
@@ -70,7 +73,7 @@ if ActiveRecord::VERSION::STRING =~ /^5\.2/
70
73
  end
71
74
  end
72
75
 
73
- scope unless scope.empty_scope?
76
+ scope
74
77
  end
75
78
  end
76
79
  end
@@ -79,19 +82,19 @@ if ActiveRecord::VERSION::STRING =~ /^5\.2/
79
82
  private
80
83
 
81
84
  def next_chain_scope(scope, reflection, next_reflection)
82
- join_keys = reflection.join_keys
83
- key = join_keys.key
84
- foreign_key = join_keys.foreign_key
85
+ primary_key = reflection.join_primary_key
86
+ foreign_key = reflection.join_foreign_key
85
87
 
86
88
  table = reflection.aliased_table
87
89
  foreign_table = next_reflection.aliased_table
88
- constraint = table[key].eq(foreign_table[foreign_key])
90
+ constraint = table[primary_key].eq(foreign_table[foreign_key])
89
91
 
90
92
  if reflection.type
91
93
  # BEGIN PATCH
92
94
  # original:
93
95
  # value = transform_value(next_reflection.klass.polymorphic_name)
94
96
  # scope = apply_scope(scope, table, reflection.type, value)
97
+
95
98
  if ActiveRecord::Base.store_base_sti_class
96
99
  value = transform_value(next_reflection.klass.polymorphic_name)
97
100
  else
@@ -110,43 +113,20 @@ if ActiveRecord::VERSION::STRING =~ /^5\.2/
110
113
  class HasManyThroughAssociation
111
114
  private
112
115
 
113
- if ActiveRecord::VERSION::STRING =~ /^5\.2\.4/
114
- def build_through_record(record)
115
- @through_records[record.object_id] ||= begin
116
- ensure_mutable
116
+ def build_through_record(record)
117
+ @through_records[record.object_id] ||= begin
118
+ ensure_mutable
117
119
 
118
- attributes = through_scope_attributes
119
- attributes[source_reflection.name] = record
120
-
121
- # START PATCH
122
- if ActiveRecord::Base.store_base_sti_class
123
- if options[:source_type]
124
- attributes[source_reflection.foreign_type] = options[:source_type]
125
- end
126
- end
127
- # END PATCH
120
+ attributes = through_scope_attributes
121
+ attributes[source_reflection.name] = record
128
122
 
129
- through_association.build(attributes)
123
+ # START PATCH
124
+ if ActiveRecord::Base.store_base_sti_class
125
+ attributes[source_reflection.foreign_type] = options[:source_type] if options[:source_type]
130
126
  end
131
- end
132
- else
133
- def build_through_record(record)
134
- @through_records[record.object_id] ||= begin
135
- ensure_mutable
136
-
137
- through_record = through_association.build(*options_for_through_record)
138
- through_record.send("#{source_reflection.name}=", record)
139
-
140
- # START PATCH
141
- if ActiveRecord::Base.store_base_sti_class
142
- if options[:source_type]
143
- through_record.send("#{source_reflection.foreign_type}=", options[:source_type])
144
- end
145
- end
146
- # END PATCH
127
+ # END PATCH
147
128
 
148
- through_record
149
- end
129
+ through_association.build(attributes)
150
130
  end
151
131
  end
152
132
  end
@@ -0,0 +1,156 @@
1
+ require 'active_record/associations/join_dependency/join_part'
2
+
3
+ if ActiveRecord::VERSION::STRING =~ /\A7\.0/
4
+ module ActiveRecord
5
+
6
+ class Base
7
+ class_attribute :store_base_sti_class
8
+ self.store_base_sti_class = true
9
+ end
10
+
11
+ module Inheritance
12
+ module ClassMethods
13
+ def polymorphic_name
14
+ ActiveRecord::Base.store_base_sti_class ? base_class.name : name
15
+ end
16
+ end
17
+ end
18
+
19
+ module Associations
20
+ class Preloader
21
+ class ThroughAssociation < Association
22
+ private
23
+
24
+ def through_scope
25
+ scope = through_reflection.klass.unscoped
26
+ options = reflection.options
27
+
28
+ values = reflection_scope.values
29
+ if annotations = values[:annotate]
30
+ scope.annotate!(*annotations)
31
+ end
32
+
33
+ if options[:source_type]
34
+ # BEGIN PATCH
35
+ # original:
36
+ # scope.where! reflection.foreign_type => options[:source_type]
37
+
38
+ adjusted_foreign_type =
39
+ if ActiveRecord::Base.store_base_sti_class
40
+ options[:source_type]
41
+ else
42
+ ([options[:source_type].constantize] + options[:source_type].constantize.descendants).map(&:to_s)
43
+ end
44
+
45
+ scope.where! reflection.foreign_type => adjusted_foreign_type
46
+ # END PATCH
47
+
48
+ elsif !reflection_scope.where_clause.empty?
49
+ scope.where_clause = reflection_scope.where_clause
50
+
51
+ if includes = values[:includes]
52
+ scope.includes!(source_reflection.name => includes)
53
+ else
54
+ scope.includes!(source_reflection.name)
55
+ end
56
+
57
+ if values[:references] && !values[:references].empty?
58
+ scope.references_values |= values[:references]
59
+ else
60
+ scope.references!(source_reflection.table_name)
61
+ end
62
+
63
+ if joins = values[:joins]
64
+ scope.joins!(source_reflection.name => joins)
65
+ end
66
+
67
+ if left_outer_joins = values[:left_outer_joins]
68
+ scope.left_outer_joins!(source_reflection.name => left_outer_joins)
69
+ end
70
+
71
+ if scope.eager_loading? && order_values = values[:order]
72
+ scope = scope.order(order_values)
73
+ end
74
+ end
75
+
76
+ scope
77
+ end
78
+ end
79
+ end
80
+
81
+ class AssociationScope
82
+ private
83
+
84
+ def next_chain_scope(scope, reflection, next_reflection)
85
+ primary_key = reflection.join_primary_key
86
+ foreign_key = reflection.join_foreign_key
87
+
88
+ table = reflection.aliased_table
89
+ foreign_table = next_reflection.aliased_table
90
+ constraint = table[primary_key].eq(foreign_table[foreign_key])
91
+
92
+ if reflection.type
93
+ # BEGIN PATCH
94
+ # original:
95
+ # value = transform_value(next_reflection.klass.polymorphic_name)
96
+ # scope = apply_scope(scope, table, reflection.type, value)
97
+
98
+ if ActiveRecord::Base.store_base_sti_class
99
+ value = transform_value(next_reflection.klass.polymorphic_name)
100
+ else
101
+ klass = next_reflection.klass
102
+ value = ([klass] + klass.descendants).map(&:name)
103
+ end
104
+ scope = apply_scope(scope, table, reflection.type, value)
105
+ # END PATCH
106
+ end
107
+
108
+ scope.joins!(join(foreign_table, constraint))
109
+ end
110
+
111
+ end
112
+
113
+ class HasManyThroughAssociation
114
+ private
115
+
116
+ def build_through_record(record)
117
+ @through_records[record.object_id] ||= begin
118
+ ensure_mutable
119
+
120
+ attributes = through_scope_attributes
121
+ attributes[source_reflection.name] = record
122
+
123
+ # START PATCH
124
+ if ActiveRecord::Base.store_base_sti_class
125
+ attributes[source_reflection.foreign_type] = options[:source_type] if options[:source_type]
126
+ end
127
+ # END PATCH
128
+
129
+ through_association.build(attributes)
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ module Reflection
136
+ class PolymorphicReflection
137
+ def source_type_scope
138
+ type = @previous_reflection.foreign_type
139
+ source_type = @previous_reflection.options[:source_type]
140
+
141
+ # START PATCH
142
+ adjusted_source_type =
143
+ if ActiveRecord::Base.store_base_sti_class
144
+ source_type
145
+ else
146
+ ([source_type.constantize] + source_type.constantize.descendants).map(&:to_s)
147
+ end
148
+ # END PATCH
149
+
150
+ lambda { |object| where(type => adjusted_source_type) }
151
+ end
152
+ end
153
+ end
154
+ end
155
+
156
+ end
@@ -1,29 +1,30 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'store_base_sti_class/version'
1
+ # frozen_string_literal: true
5
2
 
6
- Gem::Specification.new do |s|
7
- s.name = 'store_base_sti_class'
8
- s.version = StoreBaseSTIClass::VERSION
3
+ require_relative 'lib/store_base_sti_class/version'
9
4
 
10
- s.require_paths = ['lib']
11
- s.authors = ['AppFolio']
12
- s.description = "\n ActiveRecord has always stored the base class in polymorphic _type columns when using STI. This can have non-trivial\n performance implications in certain cases. This gem adds the 'store_base_sti_class' configuration option which controls\n whether ActiveRecord will store the base class or the actual class. Defaults to true for backwards compatibility.\n "
13
- s.email = 'engineering@appfolio.com'
14
- s.extra_rdoc_files = %w(
15
- LICENSE.txt
16
- README.md
17
- )
18
- s.files = Dir['**/*'].reject{ |f| f[%r{^pkg/}] || f[%r{^test/}] }
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'store_base_sti_class'
7
+ spec.version = StoreBaseSTIClass::VERSION
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.author = 'AppFolio'
10
+ spec.email = 'opensource@appfolio.com'
11
+ spec.description = <<~MSG
12
+ ActiveRecord has always stored the base class in polymorphic _type columns when using STI. This can have non-trivial
13
+ performance implications in certain cases. This gem adds the 'store_base_sti_class' configuration option which
14
+ controls whether ActiveRecord will store the base class or the actual class. Defaults to true for backwards
15
+ compatibility.'
16
+ MSG
17
+ spec.summary = <<~MSG
18
+ Modifies ActiveRecord 5.0.x - 7.0.x with the ability to store the actual class (instead of the base class) in
19
+ polymorhic _type columns when using STI.
20
+ MSG
21
+ spec.homepage = 'https://github.com/appfolio/store_base_sti_class'
22
+ spec.license = 'MIT'
23
+ spec.files = Dir['**/*'].select { |f| f[%r{^(lib/|LICENSE.txt|.*gemspec)}] }
24
+ spec.require_paths = ['lib']
25
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.3')
19
26
 
20
- s.homepage = 'http://github.com/appfolio/store_base_sti_class'
21
- s.licenses = ['MIT']
22
- s.rubygems_version = '2.2.2'
23
- s.summary = 'Modifies ActiveRecord 4.2.x - 6.0.x with the ability to store the actual class (instead of the base class) in polymorhic _type columns when using STI'
27
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
28
 
25
- s.add_runtime_dependency(%q<activerecord>, ['>= 4.0'])
26
- s.add_development_dependency(%q<minitest>, ['>= 4.0'])
27
- s.add_development_dependency(%q<appraisal>, ['>= 0'])
28
- s.add_development_dependency(%q<bundler>, ['>= 0'])
29
+ spec.add_dependency('activerecord', ['>= 6', '< 7.1'])
29
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: store_base_sti_class
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AppFolio
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-12 00:00:00.000000000 Z
11
+ date: 2022-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,93 +16,43 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '4.0'
27
- - !ruby/object:Gem::Dependency
28
- name: minitest
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '4.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '4.0'
41
- - !ruby/object:Gem::Dependency
42
- name: appraisal
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
19
+ version: '6'
20
+ - - "<"
46
21
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
22
+ version: '7.1'
23
+ type: :runtime
49
24
  prerelease: false
50
25
  version_requirements: !ruby/object:Gem::Requirement
51
26
  requirements:
52
27
  - - ">="
53
28
  - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
29
+ version: '6'
30
+ - - "<"
67
31
  - !ruby/object:Gem::Version
68
- version: '0'
69
- description: "\n ActiveRecord has always stored the base class in polymorphic _type
70
- columns when using STI. This can have non-trivial\n performance implications
71
- in certain cases. This gem adds the 'store_base_sti_class' configuration option
72
- which controls\n whether ActiveRecord will store the base class or the actual
73
- class. Defaults to true for backwards compatibility.\n "
74
- email: engineering@appfolio.com
32
+ version: '7.1'
33
+ description: |
34
+ ActiveRecord has always stored the base class in polymorphic _type columns when using STI. This can have non-trivial
35
+ performance implications in certain cases. This gem adds the 'store_base_sti_class' configuration option which
36
+ controls whether ActiveRecord will store the base class or the actual class. Defaults to true for backwards
37
+ compatibility.'
38
+ email: opensource@appfolio.com
75
39
  executables: []
76
40
  extensions: []
77
- extra_rdoc_files:
78
- - LICENSE.txt
79
- - README.md
41
+ extra_rdoc_files: []
80
42
  files:
81
- - Appraisals
82
- - Gemfile
83
- - Gemfile.lock
84
43
  - LICENSE.txt
85
- - README.md
86
- - Rakefile
87
- - gemfiles/rails_4.2.11.gemfile
88
- - gemfiles/rails_5.0.7.gemfile
89
- - gemfiles/rails_5.1.6.gemfile
90
- - gemfiles/rails_5.2.3.gemfile
91
- - gemfiles/rails_5.2.4.gemfile
92
- - gemfiles/rails_6.0.1.gemfile
93
44
  - lib/store_base_sti_class.rb
94
45
  - lib/store_base_sti_class/version.rb
95
- - lib/store_base_sti_class_for_4_2.rb
96
- - lib/store_base_sti_class_for_5_0.rb
97
- - lib/store_base_sti_class_for_5_1.rb
98
- - lib/store_base_sti_class_for_5_2.rb
99
46
  - lib/store_base_sti_class_for_6_0.rb
47
+ - lib/store_base_sti_class_for_6_1.rb
48
+ - lib/store_base_sti_class_for_7_0.rb
100
49
  - store_base_sti_class.gemspec
101
- homepage: http://github.com/appfolio/store_base_sti_class
50
+ homepage: https://github.com/appfolio/store_base_sti_class
102
51
  licenses:
103
52
  - MIT
104
- metadata: {}
105
- post_install_message:
53
+ metadata:
54
+ allowed_push_host: https://rubygems.org
55
+ post_install_message:
106
56
  rdoc_options: []
107
57
  require_paths:
108
58
  - lib
@@ -110,16 +60,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
60
  requirements:
111
61
  - - ">="
112
62
  - !ruby/object:Gem::Version
113
- version: '0'
63
+ version: 2.6.3
114
64
  required_rubygems_version: !ruby/object:Gem::Requirement
115
65
  requirements:
116
66
  - - ">="
117
67
  - !ruby/object:Gem::Version
118
68
  version: '0'
119
69
  requirements: []
120
- rubygems_version: 3.0.3
121
- signing_key:
70
+ rubygems_version: 3.3.3
71
+ signing_key:
122
72
  specification_version: 4
123
- summary: Modifies ActiveRecord 4.2.x - 6.0.x with the ability to store the actual
124
- class (instead of the base class) in polymorhic _type columns when using STI
73
+ summary: Modifies ActiveRecord 5.0.x - 7.0.x with the ability to store the actual
74
+ class (instead of the base class) in polymorhic _type columns when using STI.
125
75
  test_files: []
data/Appraisals DELETED
@@ -1,15 +0,0 @@
1
- RAILS_VERSIONS = %w[
2
- 4.2.11
3
- 5.0.7
4
- 5.1.6
5
- 5.2.3
6
- 5.2.4
7
- 6.0.1
8
- ].freeze
9
-
10
- RAILS_VERSIONS.each do |version|
11
- appraise "rails_#{version}" do
12
- gem 'activerecord', version
13
- gem 'sqlite3', version == '6.0.1' ? '~> 1.4.0' : '~> 1.3.0'
14
- end
15
- end
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,46 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- store_base_sti_class (2.0.0)
5
- activerecord (>= 4.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (6.0.1)
11
- activesupport (= 6.0.1)
12
- activerecord (6.0.1)
13
- activemodel (= 6.0.1)
14
- activesupport (= 6.0.1)
15
- activesupport (6.0.1)
16
- concurrent-ruby (~> 1.0, >= 1.0.2)
17
- i18n (>= 0.7, < 2)
18
- minitest (~> 5.1)
19
- tzinfo (~> 1.1)
20
- zeitwerk (~> 2.2)
21
- appraisal (2.2.0)
22
- bundler
23
- rake
24
- thor (>= 0.14.0)
25
- concurrent-ruby (1.1.5)
26
- i18n (1.7.0)
27
- concurrent-ruby (~> 1.0)
28
- minitest (5.13.0)
29
- rake (13.0.1)
30
- thor (0.20.3)
31
- thread_safe (0.3.6)
32
- tzinfo (1.2.5)
33
- thread_safe (~> 0.1)
34
- zeitwerk (2.2.1)
35
-
36
- PLATFORMS
37
- ruby
38
-
39
- DEPENDENCIES
40
- appraisal
41
- bundler
42
- minitest (>= 4.0)
43
- store_base_sti_class!
44
-
45
- BUNDLED WITH
46
- 1.17.2