brick 1.0.142 → 1.0.143

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e907aa4b41603045845a12d80de47e9ad714768929225b8bec209ddd9b92212
4
- data.tar.gz: 227137ba8ec83040eec6dbf76c3541f6438b7427c586690f7430572cdd59eb8a
3
+ metadata.gz: 5f3f2c35ad5ad81b538cb12c4d5166ed24bbf5e60bbc02583ed3d6f60cb38783
4
+ data.tar.gz: 2e598860e1be1b371160146ad05b8c43dfaa108c6125a1c567774fc928945a5f
5
5
  SHA512:
6
- metadata.gz: b68b20ad2ef66293dd7bdfd329c1ea341fb535e6240128beb1d5cd0dec99503ecc95b44b1adfde24f1493e4d7edb20ea61c7a4c9a1e5f6502b95c3c512261208
7
- data.tar.gz: 45722aa4054d96a858bab394a0e207e37d92ab415eb2a5832807e95d855e1c662139074bde9cf545d662a062fbe834ccd228d9595061c1dfde73990e6a3b3feb
6
+ metadata.gz: d4a99c758d21966a05f82b10d6b33865c17d85dcacb1a0c2af5d6cada712f062f30ebeab0124e7a8d31d132fe83cc265474246b2d45efa98a0b0a0c86f377cb9
7
+ data.tar.gz: 004b04e031315c1b7b96b516a55c13a7587fe109179b6ae1bd7dbe11ca305c37adfdb61b2f6c2acf26fb35cb9fbbba898c18552bc2ad050bec48fa5dec072c3d
@@ -10,6 +10,77 @@ unless ActiveRecord.respond_to?(:version)
10
10
  end
11
11
  end
12
12
 
13
+ # Allow ActiveRecord < 3.2 to work with Ruby 2.7 and later
14
+ if ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('2.7')
15
+ if ActiveRecord.version < ::Gem::Version.new('3.2')
16
+ # Remove circular reference for "now"
17
+ ::Brick::Util._patch_require(
18
+ 'active_support/values/time_zone.rb', '/activesupport',
19
+ [' def parse(str, now=now)',
20
+ ' def parse(str, now=now())']
21
+ )
22
+ # Remove circular reference for "reflection" for ActiveRecord 3.1
23
+ if ActiveRecord.version >= ::Gem::Version.new('3.1')
24
+ ::Brick::Util._patch_require(
25
+ 'active_record/associations/has_many_association.rb', '/activerecord',
26
+ ['reflection = reflection)',
27
+ 'reflection = reflection())'],
28
+ :HasManyAssociation # Make sure the path for this guy is available to be autoloaded
29
+ )
30
+ end
31
+ end
32
+
33
+ unless ActiveRecord.const_defined?(:NoDatabaseError) # Generic version of NoDatabaseError for Rails <= 4.0
34
+ require 'active_model'
35
+ require 'active_record/errors'
36
+ class ::ActiveRecord::NoDatabaseError < ::ActiveRecord::StatementInvalid
37
+ end
38
+ end
39
+
40
+ # Create unfrozen route path in Rails 3.x
41
+ if ActiveRecord.version < ::Gem::Version.new('4')
42
+ # ::Brick::Util._patch_require(
43
+ # 'action_dispatch/routing/route_set.rb', '/actiondispatch',
44
+ # ["path = (script_name.blank? ? _generate_prefix(options) : script_name.chomp('/')).to_s",
45
+ # "path = (script_name.blank? ? _generate_prefix(options) : script_name.chomp('/')).to_s.dup"]
46
+ # #,
47
+ # #:RouteSet # Make sure the path for this guy is available to be autoloaded
48
+ # )
49
+ require 'action_dispatch/routing/route_set'
50
+ # This is by no means elegant -- wish the above would work instead. Here we completely replace #url_for
51
+ # only in order to add a ".dup"
52
+ ::ActionDispatch::Routing::RouteSet.class_exec do
53
+ def url_for(options)
54
+ finalize!
55
+ options = (options || {}).reverse_merge!(default_url_options)
56
+
57
+ handle_positional_args(options)
58
+
59
+ user, password = extract_authentication(options)
60
+ path_segments = options.delete(:_path_segments)
61
+ script_name = options.delete(:script_name)
62
+
63
+ # Just adding .dup on the end in order to not have a frozen string
64
+ path = (script_name.blank? ? _generate_prefix(options) : script_name.chomp('/')).to_s.dup
65
+
66
+ path_options = options.except(*::ActionDispatch::Routing::RouteSet::RESERVED_OPTIONS)
67
+ path_options = yield(path_options) if block_given?
68
+
69
+ path_addition, params = generate(path_options, path_segments || {})
70
+
71
+ path << path_addition
72
+
73
+ ActionDispatch::Http::URL.url_for(options.merge({
74
+ :path => path,
75
+ :params => params,
76
+ :user => user,
77
+ :password => password
78
+ }))
79
+ end
80
+ end
81
+ end
82
+ end
83
+
13
84
  # ActiveSupport, ActionPack, and ActionView before 4.0 didn't have #version
14
85
  require 'active_support' # Needed for Rails 4.x
15
86
  unless ActiveSupport.respond_to?(:version)
@@ -458,17 +458,19 @@ module ActiveRecord
458
458
 
459
459
  module AttributeMethods
460
460
  module ClassMethods
461
- alias _brick_dangerous_attribute_method? dangerous_attribute_method?
462
- # Bypass the error "ActiveRecord::DangerousAttributeError" if this object comes from a view.
463
- # (Allows for column names such as 'attribute', 'delete', and 'update' to still work.)
464
- def dangerous_attribute_method?(name)
465
- if (is_dangerous = _brick_dangerous_attribute_method?(name)) && is_view?
466
- if column_names.include?(name.to_s)
467
- puts "WARNING: Column \"#{name}\" in view #{table_name} conflicts with a reserved ActiveRecord method name."
461
+ if respond_to?(:dangerous_attribute_method?)
462
+ alias _brick_dangerous_attribute_method? dangerous_attribute_method?
463
+ # Bypass the error "ActiveRecord::DangerousAttributeError" if this object comes from a view.
464
+ # (Allows for column names such as 'attribute', 'delete', and 'update' to still work.)
465
+ def dangerous_attribute_method?(name)
466
+ if (is_dangerous = _brick_dangerous_attribute_method?(name)) && is_view?
467
+ if column_names.include?(name.to_s)
468
+ puts "WARNING: Column \"#{name}\" in view #{table_name} conflicts with a reserved ActiveRecord method name."
469
+ end
470
+ return false
468
471
  end
469
- return false
472
+ is_dangerous
470
473
  end
471
- is_dangerous
472
474
  end
473
475
  end
474
476
  end
@@ -587,7 +589,7 @@ module ActiveRecord
587
589
 
588
590
  if join_array.present?
589
591
  if ActiveRecord.version < Gem::Version.new('4.2')
590
- joins!(join_array)
592
+ self.joins_values += join_array # Same as: joins!(join_array)
591
593
  else
592
594
  left_outer_joins!(join_array)
593
595
  end
@@ -1019,52 +1021,54 @@ Might want to add this in your brick.rb:
1019
1021
  module ClassMethods
1020
1022
  private
1021
1023
 
1022
- alias _brick_find_sti_class find_sti_class
1023
- def find_sti_class(type_name)
1024
- return if type_name.is_a?(Numeric)
1024
+ if respond_to?(:find_sti_class)
1025
+ alias _brick_find_sti_class find_sti_class
1026
+ def find_sti_class(type_name)
1027
+ return if type_name.is_a?(Numeric)
1025
1028
 
1026
- if ::Brick.sti_models.key?(type_name ||= name)
1027
- ::Brick.sti_models[type_name].fetch(:base, nil) || _brick_find_sti_class(type_name)
1028
- else
1029
- # This auto-STI is more of a brute-force approach, building modules where needed
1030
- # The more graceful alternative is the overload of ActiveSupport::Dependencies#autoload_module! found below
1031
- ::Brick.sti_models[type_name] = { base: self } unless type_name.blank?
1032
- module_prefixes = type_name.split('::')
1033
- module_prefixes.unshift('') unless module_prefixes.first.blank?
1034
- module_name = module_prefixes[0..-2].join('::')
1035
- if (base_name = ::Brick.config.sti_namespace_prefixes&.fetch("#{module_name}::", nil)) ||
1036
- File.exist?(candidate_file = ::Rails.root.join('app/models' + module_prefixes.map(&:underscore).join('/') + '.rb'))
1037
- if base_name
1038
- base_name == "::#{name}" ? self : base_name.constantize
1039
- else
1040
- _brick_find_sti_class(type_name) # Find this STI class normally
1041
- end
1029
+ if ::Brick.sti_models.key?(type_name ||= name)
1030
+ ::Brick.sti_models[type_name].fetch(:base, nil) || _brick_find_sti_class(type_name)
1042
1031
  else
1043
- # Build missing prefix modules if they don't yet exist
1044
- this_module = Object
1045
- module_prefixes[1..-2].each do |module_name|
1046
- this_module = if this_module.const_defined?(module_name)
1047
- this_module.const_get(module_name)
1048
- else
1049
- this_module.const_set(module_name.to_sym, Module.new)
1050
- end
1051
- end
1052
- begin
1053
- if this_module.const_defined?(class_name = module_prefixes.last.to_sym)
1054
- this_module.const_get(class_name)
1032
+ # This auto-STI is more of a brute-force approach, building modules where needed
1033
+ # The more graceful alternative is the overload of ActiveSupport::Dependencies#autoload_module! found below
1034
+ ::Brick.sti_models[type_name] = { base: self } unless type_name.blank?
1035
+ module_prefixes = type_name.split('::')
1036
+ module_prefixes.unshift('') unless module_prefixes.first.blank?
1037
+ module_name = module_prefixes[0..-2].join('::')
1038
+ if (base_name = ::Brick.config.sti_namespace_prefixes&.fetch("#{module_name}::", nil)) ||
1039
+ File.exist?(candidate_file = ::Rails.root.join('app/models' + module_prefixes.map(&:underscore).join('/') + '.rb'))
1040
+ if base_name
1041
+ base_name == "::#{name}" ? self : base_name.constantize
1055
1042
  else
1056
- # Build STI subclass and place it into the namespace module
1057
- this_module.const_set(class_name, klass = Class.new(self))
1058
- klass
1043
+ _brick_find_sti_class(type_name) # Find this STI class normally
1059
1044
  end
1060
- rescue NameError => err
1061
- if column_names.include?(inheritance_column)
1062
- puts "Table #{table_name} has column #{inheritance_column} which ActiveRecord expects to use as its special inheritance column."
1063
- puts "Unfortunately the value \"#{type_name}\" does not seem to refer to a valid type name, greatly confusing matters. If that column is intended to be used for data and not STI, consider putting this line into your Brick initializer so that only for this table that column will not clash with ActiveRecord:"
1064
- puts " Brick.sti_type_column = { 'rails_#{inheritance_column}' => ['#{table_name}'] }"
1065
- self
1066
- else
1067
- raise
1045
+ else
1046
+ # Build missing prefix modules if they don't yet exist
1047
+ this_module = Object
1048
+ module_prefixes[1..-2].each do |module_name|
1049
+ this_module = if this_module.const_defined?(module_name)
1050
+ this_module.const_get(module_name)
1051
+ else
1052
+ this_module.const_set(module_name.to_sym, Module.new)
1053
+ end
1054
+ end
1055
+ begin
1056
+ if this_module.const_defined?(class_name = module_prefixes.last.to_sym)
1057
+ this_module.const_get(class_name)
1058
+ else
1059
+ # Build STI subclass and place it into the namespace module
1060
+ this_module.const_set(class_name, klass = Class.new(self))
1061
+ klass
1062
+ end
1063
+ rescue NameError => err
1064
+ if column_names.include?(inheritance_column)
1065
+ puts "Table #{table_name} has column #{inheritance_column} which ActiveRecord expects to use as its special inheritance column."
1066
+ puts "Unfortunately the value \"#{type_name}\" does not seem to refer to a valid type name, greatly confusing matters. If that column is intended to be used for data and not STI, consider putting this line into your Brick initializer so that only for this table that column will not clash with ActiveRecord:"
1067
+ puts " Brick.sti_type_column = { 'rails_#{inheritance_column}' => ['#{table_name}'] }"
1068
+ self
1069
+ else
1070
+ raise
1071
+ end
1068
1072
  end
1069
1073
  end
1070
1074
  end
@@ -2655,7 +2659,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
2655
2659
  pg_catalog.col_description(
2656
2660
  ('\"' || t.table_schema || '\".\"' || t.table_name || '\"')::regclass::oid, c.ordinal_position
2657
2661
  ) AS column_description," if is_postgres}
2658
- c.column_name, c.data_type,
2662
+ c.column_name, #{is_postgres ? "CASE c.data_type WHEN 'USER-DEFINED' THEN pg_t.typname ELSE c.data_type END AS data_type" : 'c.data_type'},
2659
2663
  COALESCE(c.character_maximum_length, c.numeric_precision) AS max_length,
2660
2664
  kcu.constraint_type AS const, kcu.constraint_name AS \"key\",
2661
2665
  c.is_nullable
@@ -2676,7 +2680,11 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
2676
2680
  kcu.CONSTRAINT_SCHEMA = c.table_schema
2677
2681
  AND kcu.TABLE_NAME = c.table_name
2678
2682
  AND kcu.column_name = c.column_name#{"
2679
- -- AND kcu.position_in_unique_constraint IS NULL" unless is_mssql}
2683
+ -- AND kcu.position_in_unique_constraint IS NULL" unless is_mssql}#{"
2684
+ INNER JOIN pg_catalog.pg_namespace pg_n ON pg_n.nspname = t.table_schema
2685
+ INNER JOIN pg_catalog.pg_class pg_c ON pg_n.oid = pg_c.relnamespace AND pg_c.relname = c.table_name
2686
+ INNER JOIN pg_catalog.pg_attribute pg_a ON pg_c.oid = pg_a.attrelid AND pg_a.attname = c.column_name
2687
+ INNER JOIN pg_catalog.pg_type pg_t ON pg_t.oid = pg_a.atttypid" if is_postgres}
2680
2688
  WHERE t.table_schema #{is_postgres || is_mssql ?
2681
2689
  "NOT IN ('information_schema', 'pg_catalog', 'pg_toast', 'heroku_ext',
2682
2690
  'INFORMATION_SCHEMA', 'sys')"
@@ -64,7 +64,7 @@ module Brick
64
64
  if lat_lng && !(lat_lng.first.zero? && lat_lng.last.zero?)
65
65
  # Create a link to this style of Google maps URL: https://www.google.com/maps/place/38.7071296+-121.2810649/@38.7071296,-121.2810649,12z
66
66
  "<a href=\"https://www.google.com/maps/place/#{lat_lng.first}+#{lat_lng.last}/@#{lat_lng.first},#{lat_lng.last},12z\" target=\"blank\">#{val}</a>"
67
- elsif val.is_a?(Numeric)
67
+ elsif val.is_a?(Numeric) && ::ActiveSupport.const_defined?(:NumberHelper)
68
68
  ::ActiveSupport::NumberHelper.number_to_delimited(val, delimiter: ',')
69
69
  else
70
70
  ::Brick::Rails::FormBuilder.hide_bcrypt(val, col_type == :xml)
@@ -685,8 +685,8 @@ window.addEventListener(\"popstate\", linkSchemas);
685
685
  rescue StandardError => e
686
686
  # Search through the routes to confirm that something might match (Devise stuff for instance, which has its own view templates),
687
687
  # and bubble the same exception (probably an ActionView::MissingTemplate) if a legitimate option is found.
688
- raise if ::Rails.application.routes.set.find { |x| args[1].include?(x.defaults[:controller]) && args[0] == x.defaults[:action] } &&
689
- ActionView.version >= ::Gem::Version.new('5.0')
688
+ raise if ActionView.version >= ::Gem::Version.new('5.0') &&
689
+ ::Rails.application.routes.set.find { |x| args[1].include?(x.defaults[:controller]) && args[0] == x.defaults[:action] }
690
690
 
691
691
  find_template_err = e
692
692
  end
@@ -1723,7 +1723,10 @@ end
1723
1723
  case collection
1724
1724
  when ActiveRecord::Relation # has_many (which comes in as a CollectionProxy) or a has_one#{
1725
1725
  poly_fix}
1726
- collection2, descrip_cols = collection.brick_list
1726
+ collection2, descrip_cols = begin
1727
+ collection.brick_list
1728
+ rescue
1729
+ end
1727
1730
  when ActiveRecord::Base # Object from a has_one :through
1728
1731
  collection2 = [collection]
1729
1732
  else # We get an array back when AR < 4.2
@@ -41,7 +41,7 @@ module Brick::Rails::FormBuilder
41
41
  col&.type
42
42
  end
43
43
  case (col_type ||= col&.sql_type)
44
- when :string, :text
44
+ when :string, :text, :citext
45
45
  if ::Brick::Rails::FormBuilder.is_bcrypt?(val) # || .readonly?
46
46
  is_revert = false
47
47
  out << ::Brick::Rails::FormBuilder.hide_bcrypt(val, nil, 1000)
data/lib/brick/util.rb CHANGED
@@ -32,9 +32,6 @@ module Brick
32
32
  !alp.include?(custom_require_dir)
33
33
  alp.unshift(custom_require_dir)
34
34
  end
35
- # require 'pry-byebug'
36
- # binding.pry
37
- # z = 10
38
35
  elsif is_bundler
39
36
  puts "Bundler hack"
40
37
  require 'pry-byebug'
@@ -52,12 +49,11 @@ module Brick
52
49
  # then required in place of the original.
53
50
 
54
51
  Kernel.module_exec do
55
- # class << self
56
52
  alias_method :orig_require, :require
57
- # end
58
53
  # To be most faithful to Ruby's normal behaviour, this should look like a public singleton
59
54
  define_method(:require) do |name|
60
- puts name if name.to_s.include?('cucu')
55
+ # %%% Can get a message such as "ActionDispatch::Routing is not missing constant RouteSet! (NameError)"
56
+ # binding.pry if name.start_with?('action_dispatch/routing/route_') # || name == 'active_support/values/time_zone'
61
57
  if (require_override = ::Brick::Util.instance_variable_get(:@_require_overrides)[name])
62
58
  extension, folder_matcher, replacements, autoload_symbol = require_override
63
59
  patched_filename = "/patched_#{name.tr('/', '_')}#{extension}"
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 142
8
+ TINY = 143
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
data/lib/brick.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'brick/compatibility'
4
+ ruby_version = ::Gem::Version.new(RUBY_VERSION)
4
5
 
5
6
  # Allow ActiveRecord 4.2.7 and older to work with newer Ruby (>= 2.4) by avoiding a "stack level too deep"
6
7
  # error when ActiveSupport tries to smarten up Numeric by messing with Fixnum and Bignum at the end of:
@@ -25,37 +26,6 @@ end
25
26
 
26
27
  require 'brick/util'
27
28
 
28
- # Allow ActiveRecord < 3.2 to work with Ruby 2.7 and later
29
- if (is_ruby_2_7 = (ruby_version = ::Gem::Version.new(RUBY_VERSION)) >= ::Gem::Version.new('2.7'))
30
- if ActiveRecord.version < ::Gem::Version.new('3.2')
31
- # Remove circular reference for "now"
32
- ::Brick::Util._patch_require(
33
- 'active_support/values/time_zone.rb', '/activesupport',
34
- [' def parse(str, now=now)',
35
- ' def parse(str, now=now())']
36
- )
37
- # Remove circular reference for "reflection" for ActiveRecord 3.1
38
- if ActiveRecord.version >= ::Gem::Version.new('3.1')
39
- ::Brick::Util._patch_require(
40
- 'active_record/associations/has_many_association.rb', '/activerecord',
41
- ['reflection = reflection)',
42
- 'reflection = reflection())'],
43
- :HasManyAssociation # Make sure the path for this guy is available to be autoloaded
44
- )
45
- end
46
- end
47
-
48
- # # Create unfrozen route path in Rails 3.2
49
- # if ActiveRecord.version < ::Gem::Version.new('4')
50
- # ::Brick::Util._patch_require(
51
- # 'action_dispatch/routing/route_set.rb', '/actiondispatch',
52
- # ["script_name.chomp('/')).to_s",
53
- # "script_name.chomp('/')).to_s.dup"],
54
- # :RouteSet # Make sure the path for this guy is available to be autoloaded
55
- # )
56
- # end
57
- end
58
-
59
29
  # Add left_outer_joins! to Associations::JoinDependency and Relation::QueryMethods
60
30
  if ActiveRecord.version >= ::Gem::Version.new('4') && ActiveRecord.version < ::Gem::Version.new('5')
61
31
  ::Brick::Util._patch_require(
@@ -163,7 +133,8 @@ module Brick
163
133
 
164
134
  # All tables and views (what Postgres calls "relations" including column and foreign key info)
165
135
  def relations
166
- return {} if ::ActiveRecord::Base.connection_handler.connection_pool_list.blank?
136
+ return {} if (ch = ::ActiveRecord::Base.connection_handler).respond_to?(:connection_pool_list) &&
137
+ ch.connection_pool_list.blank?
167
138
 
168
139
  # Key our list of relations for this connection off of the connection pool's object_id
169
140
  (@relations ||= {})[ActiveRecord::Base.connection_pool.object_id] ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = {} } }
@@ -946,20 +917,22 @@ In config/initializers/brick.rb appropriate entries would look something like:
946
917
  end
947
918
  end
948
919
 
949
- if ::Brick.config.add_status && (status_as = "#{controller_prefix.tr('/', '_')}brick_status".to_sym)
950
- (
951
- !(status_route = instance_variable_get(:@set).named_routes.find { |route| route.first == status_as }&.last) ||
952
- !status_route.ast.to_s.include?("/#{controller_prefix}brick_status/")
953
- )
954
- get("/#{controller_prefix}brick_status", to: 'brick_gem#status', as: status_as.to_s)
955
- end
920
+ if (named_routes = instance_variable_get(:@set).named_routes).respond_to?(:find)
921
+ if ::Brick.config.add_status && (status_as = "#{controller_prefix.tr('/', '_')}brick_status".to_sym)
922
+ (
923
+ !(status_route = instance_variable_get(:@set).named_routes.find { |route| route.first == status_as }&.last) ||
924
+ !status_route.ast.to_s.include?("/#{controller_prefix}brick_status/")
925
+ )
926
+ get("/#{controller_prefix}brick_status", to: 'brick_gem#status', as: status_as.to_s)
927
+ end
956
928
 
957
- if ::Brick.config.add_orphans && (orphans_as = "#{controller_prefix.tr('/', '_')}brick_orphans".to_sym)
958
- (
959
- !(orphans_route = instance_variable_get(:@set).named_routes.find { |route| route.first == orphans_as }&.last) ||
960
- !orphans_route.ast.to_s.include?("/#{controller_prefix}brick_orphans/")
961
- )
962
- get("/#{controller_prefix}brick_orphans", to: 'brick_gem#orphans', as: 'brick_orphans')
929
+ if ::Brick.config.add_orphans && (orphans_as = "#{controller_prefix.tr('/', '_')}brick_orphans".to_sym)
930
+ (
931
+ !(orphans_route = instance_variable_get(:@set).named_routes.find { |route| route.first == orphans_as }&.last) ||
932
+ !orphans_route.ast.to_s.include?("/#{controller_prefix}brick_orphans/")
933
+ )
934
+ get("/#{controller_prefix}brick_orphans", to: 'brick_gem#orphans', as: 'brick_orphans')
935
+ end
963
936
  end
964
937
 
965
938
  if instance_variable_get(:@set).named_routes.names.exclude?(:brick_crosstab)
@@ -1030,7 +1003,11 @@ require 'brick/version_number'
1030
1003
  if (is_postgres = (Object.const_defined?('PG::VERSION') || Gem::Specification.find_all_by_name('pg').present?)) &&
1031
1004
  ActiveRecord.version < ::Gem::Version.new('4.2.6')
1032
1005
  ::Brick::Util._patch_require(
1033
- 'active_record/connection_adapters/postgresql_adapter.rb', '/activerecord', ["'panic'", "'error'"]
1006
+ 'active_record/connection_adapters/postgresql_adapter.rb', '/activerecord', [
1007
+ ["'panic'", "'error'"],
1008
+ # ActiveRecord < 3.2.13 uses the pg_attrdef.adsrc column, but it's missing in Postgres 12 and later, so we need to use pg_get_expr(d.adbin, d.adrelid).
1009
+ [', d.adsrc,', ', pg_get_expr(d.adbin, d.adrelid),']
1010
+ ]
1034
1011
  )
1035
1012
  end
1036
1013
 
@@ -1317,8 +1294,8 @@ ActiveSupport.on_load(:active_record) do
1317
1294
  end
1318
1295
  # rubocop:enable Lint/ConstantDefinitionInBlock
1319
1296
 
1320
- arsc = ::ActiveRecord::StatementCache
1321
- if is_ruby_2_7 && arsc.respond_to?(:create) &&
1297
+ if ruby_version >= ::Gem::Version.new('2.7') && ::ActiveRecord.const_defined?(:StatementCache) &&
1298
+ (arsc = ::ActiveRecord::StatementCache).respond_to?(:create) &&
1322
1299
  (params = arsc.method(:create).parameters).length == 2 && params.last == [:opt, :block]
1323
1300
  arsc.class_exec do
1324
1301
  def self.create(connection, callable = nil, &block)
@@ -1423,14 +1400,18 @@ ActiveSupport.on_load(:active_record) do
1423
1400
  elsif araat.respond_to?(:create) # Rails 4.1 and 4.2
1424
1401
  @alias_tracker = araat.create(base.connection, joins)
1425
1402
  @alias_tracker.aliased_table_for(base, base.table_name) # Updates the count for base.table_name to 1
1426
- else # Rails 4.0
1403
+ else # Rails <= 4.0
1427
1404
  is_rails_4 = true
1428
1405
  @base_klass = base
1429
1406
  @table_joins = joins
1430
1407
  @join_parts = [JoinBase.new(base)]
1431
1408
  @associations = {}
1432
1409
  @reflections = []
1433
- @alias_tracker = araat.new(base.connection, joins)
1410
+ @alias_tracker = if araat.instance_method(:initialize).parameters.length == 2 # Rails > 3.2.8
1411
+ araat.new(base.connection, joins)
1412
+ else
1413
+ araat.new(joins)
1414
+ end
1434
1415
  @alias_tracker.aliased_name_for(base.table_name) # Updates the count for base.table_name to 1
1435
1416
  tree = build(associations)
1436
1417
  end
@@ -1441,7 +1422,7 @@ ActiveSupport.on_load(:active_record) do
1441
1422
  if (relation = associations.instance_variable_get(:@relation))
1442
1423
  tree.instance_variable_set(:@relation, relation)
1443
1424
  end
1444
- return if is_rails_4 # Rails 4.0 doesn't know about the rest
1425
+ return if is_rails_4 # Rails <= 4.0 doesn't know about the rest
1445
1426
 
1446
1427
  @join_root = JoinBase.new base, build(tree, base)
1447
1428
  @join_root.children.each { |child| construct_tables! @join_root, child }
@@ -1618,7 +1599,7 @@ module ActiveRecord
1618
1599
  _brick_build_join_query(manager, buckets, *args) # , **kwargs)
1619
1600
  end
1620
1601
 
1621
- else # elsif private_instance_methods.include?(:select_association_list)
1602
+ elsif private_instance_methods.include?(:select_association_list)
1622
1603
  alias _brick_select_association_list select_association_list
1623
1604
  def select_association_list(associations, stashed_joins = nil)
1624
1605
  result = _brick_select_association_list(associations, stashed_joins)
@@ -137,7 +137,8 @@ module Brick
137
137
  fringe.each do |tbl|
138
138
  next unless (relation = ::Brick.relations.fetch(tbl, nil))&.fetch(:cols, nil)&.present?
139
139
 
140
- pkey_cols = (rpk = relation[:pkey].values.flatten) & (arpk = [ApplicationRecord.primary_key].flatten.sort)
140
+ ar_base = Object.const_defined?(:ApplicationRecord) ? ApplicationRecord : Class.new(ActiveRecord::Base)
141
+ pkey_cols = (rpk = relation[:pkey].values.flatten) & (arpk = [ar_base.primary_key].flatten.sort)
141
142
  # In case things aren't as standard
142
143
  if pkey_cols.empty?
143
144
  pkey_cols = if rpk.empty? && relation[:cols][arpk.first]&.first == key_type
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.142
4
+ version: 1.0.143
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-17 00:00:00.000000000 Z
11
+ date: 2023-05-19 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: '3.0'
19
+ version: 3.1.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: '3.0'
26
+ version: 3.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fancy_gets
29
29
  requirement: !ruby/object:Gem::Requirement