brick 1.0.205 → 1.0.206

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: 3abdf25aeb401676febcc1ea98ce104a9e005ecae652f17daf3736baab63d5ea
4
- data.tar.gz: 195eb8e27607f719808954914a409b356c249384cacd0535fab65652b02cd4ec
3
+ metadata.gz: 7cd4c557cd4baa06fc68ab683444da5b018c1c0c63436d36d7648c259167c418
4
+ data.tar.gz: 62d2260128b72a0a6db5d0af14054ae9518e4516ccf18a04010d2e187c8768d2
5
5
  SHA512:
6
- metadata.gz: 187b1740a3f0e54f061c9b293df233c32993eb00ca4a218e1b32b7888c8b72c4fb9d2889ec7a2a469f95d3b39242b9adc8c02167c76065a5dcfd45262714793c
7
- data.tar.gz: 132fecbea3bcf8783a0ad2ca540747af4a74e882d0fdba60bf0491c0ee19e52e9ef378d6a39ab3df89cbac3bcd6dee760959f969f45e17587b6a0b643f9e1bb3
6
+ metadata.gz: 43743d8447db6daa39e2fc506e7eef3260ba63abc3a4cb4990ace1d33e56e38d15dd7eaf9c9bbdb2873ea2b5dae6d308c12bd04ea2f073b04fefccac564ee3e3
7
+ data.tar.gz: 144317e91f03fdf2ca66db2c78d8f851e9ab21c4c016190ad3a48ef97a3594f2df8125a1d4f4a59214501429e1c16b6baca9878c22bb2d026eeee20a83929f53
@@ -536,10 +536,35 @@ module ActiveRecord
536
536
  class Relation
537
537
  attr_accessor :_brick_page_num
538
538
 
539
- # Links from ActiveRecord association pathing names over to real table correlation names
540
- # that get chosen when the AREL AST tree is walked.
539
+ # Links from ActiveRecord association pathing names over to the real table
540
+ # correlation names that get chosen when the AREL AST tree is walked.
541
541
  def brick_links
542
- @brick_links ||= { '' => table_name }
542
+ # Touching AREL AST walks the JoinDependency tree, and in that process uses our
543
+ # "brick_links" patch to find how every AR chain of association names relates to exact
544
+ # table correlation names chosen by AREL. We use a duplicate relation object for this
545
+ # because an important side-effect of referencing the AST is that the @arel instance
546
+ # variable gets set, and this is a signal to ActiveRecord that a relation has now
547
+ # become immutable. (We aren't quite ready for our "real deal" relation object to be
548
+ # set in stone ... still need to add .select(), and possibly .where() and .order()
549
+ # things ... also if there are any HM counts then an OUTER JOIN for each of them out
550
+ # to a derived table to do that counting. All of these things need to know proper
551
+ # table correlation names, which will now become available from brick_links on the
552
+ # @_brick_rel_dupe object.)
553
+ @_brick_links ||= begin
554
+ # If it's a CollectionProxy (which inherits from Relation) then need to dig
555
+ # out the core Relation object which is found in the association scope.
556
+ rel_dupe = (is_a?(ActiveRecord::Associations::CollectionProxy) ? scope : self).dup
557
+ # This will become a fully populated hash of correlation names
558
+ rel_dupe.instance_variable_set(:@_brick_links, bl = { '' => table_name })
559
+ # Walk the AST tree in order to capture all the correlation names
560
+ rel_dupe.arel.ast
561
+ # Now that @_brick_links are captured, we can garbage collect the @_brick_rel_dupe object
562
+ # remove_instance_variable(:@_brick_rel_dupe)
563
+ bl
564
+ end
565
+ # if @_brick_rel_dupe
566
+ # end
567
+ # @_brick_links
543
568
  end
544
569
 
545
570
  def brick_select(*args, params: {}, order_by: nil, translations: {},
@@ -648,23 +673,6 @@ module ActiveRecord
648
673
  end
649
674
  end
650
675
 
651
- # If it's a CollectionProxy (which inherits from Relation) then need to dig out the
652
- # core Relation object which is found in the association scope.
653
- rel_dupe = (is_a?(ActiveRecord::Associations::CollectionProxy) ? scope : self).dup
654
-
655
- # Touching AREL AST walks the JoinDependency tree, and in that process uses our
656
- # "brick_links" patch to find how every AR chain of association names relates to exact
657
- # table correlation names chosen by AREL. We use a duplicate relation object for this
658
- # because an important side-effect of referencing the AST is that the @arel instance
659
- # variable gets set, and this is a signal to ActiveRecord that a relation has now
660
- # become immutable. (We aren't quite ready for our "real deal" relation object to be
661
- # set in stone ... still need to add .select(), and possibly .where() and .order()
662
- # things ... also if there are any HM counts then an OUTER JOIN for each of them out
663
- # to a derived table to do that counting. All of these things need to know proper
664
- # table correlation names, which will now become available in brick_links on the
665
- # rel_dupe object.)
666
- rel_dupe.arel.ast
667
-
668
676
  core_selects = selects.dup
669
677
  id_for_tables = Hash.new { |h, k| h[k] = [] }
670
678
  field_tbl_names = Hash.new { |h, k| h[k] = {} }
@@ -673,7 +681,7 @@ module ActiveRecord
673
681
  # CUSTOM COLUMNS
674
682
  # ==============
675
683
  (cust_col_override || klass._br_cust_cols).each do |k, cc|
676
- if rel_dupe.respond_to?(k) # Name already taken?
684
+ if respond_to?(k) # Name already taken?
677
685
  # %%% Use ensure_unique here in this kind of fashion:
678
686
  # cnstr_name = ensure_unique(+"(brick) #{for_tbl}_#{pri_tbl}", nil, bts, hms)
679
687
  # binding.pry
@@ -690,7 +698,7 @@ module ActiveRecord
690
698
  # binding.pry unless kl.reflect_on_association(cc_part_term)
691
699
  kl.reflect_on_association(cc_part_term)&.klass || klass
692
700
  end
693
- tbl_name = rel_dupe.brick_links[cc_part[0..-2].map(&:to_s).join('.')]
701
+ tbl_name = brick_links[cc_part[0..-2].map(&:to_s).join('.')]
694
702
  # Deal with the conflict if there are two parts in the custom column named the same,
695
703
  # "category.name" and "product.name" for instance will end up with aliases of "name"
696
704
  # and "product__name".
@@ -734,19 +742,19 @@ module ActiveRecord
734
742
  unless cust_col_override
735
743
  klass._br_bt_descrip.each do |v|
736
744
  v.last.each do |k1, v1| # k1 is class, v1 is array of columns to snag
737
- next unless (tbl_name = rel_dupe.brick_links[v.first.to_s]&.split('.')&.last)
745
+ next unless (tbl_name = brick_links[v.first.to_s]&.split('.')&.last)
738
746
 
739
747
  # If it's Oracle, quote any AREL aliases that had been applied
740
- tbl_name = "\"#{tbl_name}\"" if ::Brick.is_oracle && rel_dupe.brick_links.values.include?(tbl_name)
748
+ tbl_name = "\"#{tbl_name}\"" if ::Brick.is_oracle && brick_links.values.include?(tbl_name)
741
749
  field_tbl_name = nil
742
750
  v1.map { |x| [x[0..-2].map(&:to_s).join('.'), x.last] }.each_with_index do |sel_col, idx|
743
751
  # %%% Strangely in Rails 7.1 on a slower system then very rarely brick_link comes back nil...
744
- brick_link = rel_dupe.brick_links[sel_col.first]
752
+ brick_link = brick_links[sel_col.first]
745
753
  field_tbl_name = brick_link&.split('.')&.last ||
746
754
  # ... so here's a best-effort guess for what the table name might be.
747
- rel_dupe.klass.reflect_on_association(sel_col.first)&.klass&.table_name
755
+ klass.reflect_on_association(sel_col.first)&.klass&.table_name
748
756
  # If it's Oracle, quote any AREL aliases that had been applied
749
- field_tbl_name = "\"#{field_tbl_name}\"" if ::Brick.is_oracle && rel_dupe.brick_links.values.include?(field_tbl_name)
757
+ field_tbl_name = "\"#{field_tbl_name}\"" if ::Brick.is_oracle && brick_links.values.include?(field_tbl_name)
750
758
 
751
759
  # Postgres can not use DISTINCT with any columns that are XML, so for any of those just convert to text
752
760
  is_xml = is_distinct && Brick.relations[k1.table_name]&.[](:cols)&.[](sel_col.last)&.first&.start_with?('xml')
@@ -788,7 +796,7 @@ module ActiveRecord
788
796
  join_array.each do |assoc_name|
789
797
  next unless assoc_name.is_a?(Symbol)
790
798
 
791
- table_alias = rel_dupe.brick_links[assoc_name.to_s]
799
+ table_alias = brick_links[assoc_name.to_s]
792
800
  _assoc_names[assoc_name] = [table_alias, klass]
793
801
  end
794
802
  end
@@ -931,7 +939,7 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
931
939
  if (v_parts = v.first.split('.')).length == 1
932
940
  (is_not ? where_nots : s)[v.first] = v.last
933
941
  else
934
- tbl_name = rel_dupe.brick_links[v_parts.first].split('.').last
942
+ tbl_name = brick_links[v_parts.first].split('.').last
935
943
  (is_not ? where_nots : s)["#{tbl_name}.#{v_parts.last}"] = v.last
936
944
  end
937
945
  end
@@ -1042,10 +1050,9 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
1042
1050
  else
1043
1051
  self.joins!(ja)
1044
1052
  end
1045
- (ast_tree = self.dup).arel.ast # Walk the AST tree so we can rewrite the prefixes accordingly
1046
1053
  conditions = opts.each_with_object({}) do |v, s|
1047
1054
  if (ref_parts = v.first.split('.')).length > 1 &&
1048
- (tbl = ast_tree.brick_links[ref_parts[0..-2].join('.')])
1055
+ (tbl = brick_links[ref_parts[0..-2].join('.')])
1049
1056
  s["#{tbl}.#{ref_parts.last}"] = v.last
1050
1057
  else
1051
1058
  s[v.first] = v.last
@@ -1315,10 +1322,15 @@ end
1315
1322
  # Try to require the respective Ruby file
1316
1323
  # ((filename = ActiveSupport::Dependencies.search_for_file(desired_classname.underscore)) &&
1317
1324
  # (require_dependency(filename) || true) &&
1318
- ((filename = ActiveSupport::Dependencies.search_for_file(desired_classname.underscore) ||
1325
+ (!anonymous? &&
1326
+ (filename = ActiveSupport::Dependencies.search_for_file(desired_classname.underscore) ||
1319
1327
  (self != Object && ActiveSupport::Dependencies.search_for_file((desired_classname = requested).underscore))
1320
1328
  ) && (require_dependency(filename) || true) &&
1321
- (!anonymous? && (possible = self.const_get(args.first)) && possible.name == desired_classname)
1329
+ (filename != Module.instance_variable_get(:@_brick_last_filename) || # Avoid trying the same exact file twice in a row
1330
+ Module.instance_variable_set(:@_brick_last_filename, nil)) &&
1331
+ Module.instance_variable_set(:@_brick_last_filename, filename) &&
1332
+
1333
+ (possible = self.const_get(args.first)) && possible.name == desired_classname
1322
1334
  ) ||
1323
1335
 
1324
1336
  # If any class has turned up so far (and we're not in the middle of eager loading)
@@ -1337,6 +1349,7 @@ end
1337
1349
  return possible
1338
1350
  end
1339
1351
  end
1352
+ Module.instance_variable_set(:@_brick_last_filename, nil) # Clear out the check for trying the same exact file twice in a row
1340
1353
  end
1341
1354
  class_name = ::Brick.namify(requested)
1342
1355
  is_avo_present = Object.const_defined?('Avo') && ::Avo.respond_to?(:railtie_namespace)
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 205
8
+ TINY = 206
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
@@ -1560,9 +1560,7 @@ module ActiveRecord
1560
1560
  used_cols = {}
1561
1561
  # Find and expand out all column names being used in select(...)
1562
1562
  new_select_values = relation.select_values.map(&:to_s).each_with_object([]) do |col, s|
1563
- if col.include?(' ') # Some expression? (No chance for a simple column reference)
1564
- s << col # Just pass it through
1565
- else
1563
+ unless col.include?(' ') # Pass it through if it's some expression (No chance for a simple column reference)
1566
1564
  col = if (col_parts = col.split('.')).length == 1
1567
1565
  [col]
1568
1566
  else
@@ -1570,6 +1568,7 @@ module ActiveRecord
1570
1568
  end
1571
1569
  used_cols[col] = nil
1572
1570
  end
1571
+ s << col
1573
1572
  end
1574
1573
  if new_select_values.present?
1575
1574
  relation.select_values = new_select_values
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.205
4
+ version: 1.0.206
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-25 00:00:00.000000000 Z
11
+ date: 2024-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -285,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
285
  - !ruby/object:Gem::Version
286
286
  version: 1.3.6
287
287
  requirements: []
288
- rubygems_version: 3.1.6
288
+ rubygems_version: 3.2.33
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: Create a Rails app from data alone