store_base_sti_class 2.0.3 → 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: 5e65e14ac35f409bec5e78c411a0b3fac80ca189d8e77f693fc2ecc9f4cf609d
4
- data.tar.gz: c0aabbee8bba07b1818f5f2fca9f94a916f56e29bcff73d9f1919fa53d269bcc
3
+ metadata.gz: 6bfa35237d6d92294c821edbb70e75070df5109027f984e567ea4d372cdbb5b1
4
+ data.tar.gz: c99a988b260c44d272790ae8e0ac47a09d3d75f2b248f4dab4759b63b7cff3f3
5
5
  SHA512:
6
- metadata.gz: 6078f16de9958cead9799a9da35830c2c031c17bbead961b801f6194905e65e43ab6f002ab34fd34ef6431e0b8f9ab1fc52b0c502372a3957a768480459df882
7
- data.tar.gz: 22e514b7f2ce662d2cfa8f8fe6b2bc62f4491defe8b182c76121922f01ca7929146f546cfb7eab0d8d42ba8417c4343ae54d616cb949a44bba48c98fa5b0469f
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.3'.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 =~ /^5\.0/
4
- require 'store_base_sti_class_for_5_0'
5
- elsif ActiveRecord::VERSION::STRING =~ /^5\.1/
6
- require 'store_base_sti_class_for_5_1'
7
- elsif ActiveRecord::VERSION::STRING =~ /^5\.2/
8
- require 'store_base_sti_class_for_5_2'
9
- elsif ActiveRecord::VERSION::STRING =~ /^6\.0/
10
- require 'store_base_sti_class_for_6_0'
11
- elsif ActiveRecord::VERSION::STRING =~ /^6\.1/
12
- require 'store_base_sti_class_for_6_1'
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 =~ /\A7\.0/
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 Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('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
@@ -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.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AppFolio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-31 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,92 +16,42 @@ 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
43
  - LICENSE.txt
84
- - README.md
85
- - Rakefile
86
- - gemfiles/rails_5.0.7.gemfile
87
- - gemfiles/rails_5.1.7.gemfile
88
- - gemfiles/rails_5.2.3.gemfile
89
- - gemfiles/rails_5.2.4.gemfile
90
- - gemfiles/rails_5.2.5.gemfile
91
- - gemfiles/rails_6.0.3.gemfile
92
- - gemfiles/rails_6.1.0.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_5_0.rb
96
- - lib/store_base_sti_class_for_5_1.rb
97
- - lib/store_base_sti_class_for_5_2.rb
98
46
  - lib/store_base_sti_class_for_6_0.rb
99
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: {}
53
+ metadata:
54
+ allowed_push_host: https://rubygems.org
105
55
  post_install_message:
106
56
  rdoc_options: []
107
57
  require_paths:
@@ -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.2.3
70
+ rubygems_version: 3.3.3
121
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
- 5.0.7
3
- 5.1.7
4
- 5.2.3
5
- 5.2.4
6
- 6.0.3
7
- 6.1.0
8
- ].freeze
9
-
10
- RAILS_VERSIONS.each do |version|
11
- appraise "rails_#{version}" do
12
- gem 'activerecord', version
13
- gem 'sqlite3', ['6.0.3', '6.1.0'].include?(version) ? '~> 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/README.md DELETED
@@ -1,101 +0,0 @@
1
- [![CI](https://github.com/appfolio/store_base_sti_class/workflows/CI/badge.svg)](https://github.com/appfolio/store_base_sti_class/actions)
2
-
3
- ## Description
4
-
5
- Given the following class definitions:
6
-
7
- ```ruby
8
- class Address
9
- belongs_to :addressable, :polymorphic => true
10
- end
11
-
12
- class Person
13
- has_many :addresses, :as => addressable
14
- end
15
-
16
- class Vendor < Person
17
- end
18
- ```
19
-
20
- and given the following code:
21
-
22
- ```ruby
23
- vendor = Vendor.create(...)
24
- address = vendor.addresses.create(...)
25
-
26
- p vendor
27
- p address
28
- ```
29
-
30
- will output:
31
-
32
- ```ruby
33
- #<Vendor id: 1, type: "Vendor" ...>
34
- #<Address id: 1, addressable_id: 1, addressable_type: 'Person' ...>
35
- ```
36
-
37
- Notice that addressable_type column is Person even though the actual class is Vendor.
38
-
39
- Normally, this isn't a problem, however, it can have negative performance
40
- characteristics in certain circumstances. The most obvious one is that a join
41
- with persons or an extra query is required to find out the actual type of
42
- addressable.
43
-
44
- This gem adds the ActiveRecord::Base.store_base_sti_class configuration
45
- option. It defaults to true for backwards compatibility. Setting it to false
46
- will alter ActiveRecord's behavior to store the actual class in polymorphic
47
- _type columns when STI is used.
48
-
49
- In the example above, if the ActiveRecord::Base.store_base_sti_class is false, the output will be,
50
-
51
- ```
52
- #<Vendor id: 1, type: "Vendor" ...>
53
- #<Address id: 1, addressable_id: 1, addressable_type: 'Vendor' ...>
54
- ```
55
-
56
- ## Usage
57
-
58
- Add the following line to your Gemfile,
59
-
60
- ```ruby
61
- gem 'store_base_sti_class'
62
- ```
63
-
64
- then bundle install. Once you have the gem installed, add the following to one
65
- of the initializers (or make a new one) in config/initializers,
66
-
67
- ActiveRecord::Base.store_base_sti_class = false
68
-
69
- When changing this behavior, you will have write a migration to update all of
70
- your existing _type columns accordingly. You may also need to change your
71
- application if it explicitly relies on the _type columns.
72
-
73
- ## Notes
74
-
75
- This gem incorporates work from:
76
-
77
- - https://github.com/codepodu/store_base_sti_class_for_4_0
78
-
79
- It currently works with ActiveRecord 4.2.x through 6.0.x. If you need support
80
- for ActiveRecord 3.x, use a pre-1.0 version of the gem, or ActiveRecord < 4.2
81
- use a pre-2.0 version of the gem.
82
-
83
- ## Conflicts
84
-
85
- This gem produces known conflicts with these other gems:
86
-
87
- ### friendly_id
88
-
89
- When using [friendly_id](https://github.com/norman/friendly_id) >= 5.2.5 with the [History module](https://norman.github.io/friendly_id/FriendlyId/History.html) enabled, duplicate slugs will be generated for STI subclasses with the same sluggable identifier (ex: name). This will either cause saves to fail if you have the proper indexes in place, or will cause slug lookups to be non-deterministic, either of which is undesirable.
90
-
91
- ## History
92
-
93
- * https://github.com/rails/rails/issues/724
94
- * https://github.com/rails/rails/issues/5441#issuecomment-4563865
95
- * https://github.com/rails/rails/issues/4729#issuecomment-5729297
96
- * https://github.com/rails/rails/issues/5441#issuecomment-264871920
97
-
98
- ## Copyright
99
-
100
- Copyright (c) 2011-2019 AppFolio, inc. See LICENSE.txt for
101
- further details.
data/Rakefile DELETED
@@ -1,23 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- require 'appraisal'
5
-
6
- begin
7
- Bundler.setup(:default, :development)
8
- rescue Bundler::BundlerError => e
9
- $stderr.puts e.message
10
- $stderr.puts "Run `bundle install` to install missing gems"
11
- exit e.status_code
12
- end
13
- require 'rake'
14
-
15
- require 'rake/testtask'
16
- Rake::TestTask.new(:test) do |test|
17
- test.libs << 'lib' << 'test'
18
- test.pattern = 'test/**/test_*.rb'
19
- test.verbose = true
20
- end
21
-
22
- task :default => :test
23
-
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.0.7"
6
- gem "sqlite3", "~> 1.3.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.1.7"
6
- gem "sqlite3", "~> 1.3.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.2.3"
6
- gem "sqlite3", "~> 1.3.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.2.4"
6
- gem "sqlite3", "~> 1.3.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "5.2.5"
6
- gem "sqlite3", "~> 1.3.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "6.0.3"
6
- gem "sqlite3", "~> 1.4.0"
7
-
8
- gemspec path: "../"
@@ -1,8 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "6.1.0"
6
- gem "sqlite3", "~> 1.4.0"
7
-
8
- gemspec path: "../"