brick 1.0.209 → 1.0.210

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: 9727d5ff3dbf5edcb8ce91b03d0570eec5eb2e0f9ae2c4f456d9d50779321fc9
4
- data.tar.gz: 32b32f909110d6eca464c775d9725ad049fabf8591daab1088da007ae9a95c5a
3
+ metadata.gz: 803d4790408a0b789ff8086b5b81346581071b260cbc528039fd8cfa8894b7ac
4
+ data.tar.gz: 4503e1b9feba62d33e83f3fadc25a34b70bf9c661dc750187a3c391e3b24d5e8
5
5
  SHA512:
6
- metadata.gz: 1931290e472f472d93e1536e6517a3865bcc1acd23d15156d48e52c7f35987183b274c8a7c2ac00f09f2f6ac9a4d5663071c84ae4c896de6b4c0069d4a06b1da
7
- data.tar.gz: 5064ef883fb66feb187fe80a92b3ec700da04feef0f390d720b51497f086bbc1062e505cd467d3624fadb6102bc8dec49b0b6b16a1c04a1a1ceb34e50f4f9ff5
6
+ metadata.gz: 1fe28c2a9ca30ef663f28fe79e65e1b2787686c6fce6d5738d9b6addd6070437411d5210e1ba641b28eae5215fb37756f3faa80f246d823d5d553c9db990a427
7
+ data.tar.gz: daa9bb88c21467075717062c1ede0ab38af4207bf96d9a2495ce84f99850a4d0cb09f4c1c95017cb3862ef915fab85036397375d43518f7bee2d7bd6f1255aed
@@ -72,7 +72,7 @@ module ActiveRecord
72
72
 
73
73
  def real_model(params)
74
74
  if params && (sub_model = params.fetch(type_col = inheritance_column, nil))
75
- sub_model = sub_model.first if sub_model.is_a?(Array) # Support the params style that gets returned from #brick_select
75
+ sub_model = sub_model.first if sub_model.is_a?(Array) # Support the params style that gets returned from #_brick_querying
76
76
  # Make sure the chosen model is really the same or a subclass of this model
77
77
  (possible_model = sub_model.constantize) <= self ? possible_model : self
78
78
  else
@@ -491,17 +491,12 @@ module ActiveRecord
491
491
  [order_by, order_by_txt]
492
492
  end
493
493
 
494
- def self.brick_select(*args, params: {}, brick_col_names: false, **kwargs)
495
- selects = if args[0].is_a?(Array)
496
- other_args = args[1..-1]
497
- args[0]
498
- else
499
- other_args = []
500
- args
501
- end
502
- (relation = all).brick_select(selects, *other_args,
503
- params: params, brick_col_names: brick_col_names, **kwargs)
504
- relation.select(selects)
494
+ def self.brick_select(*args, **kwargs)
495
+ all.brick_select(*args, **kwargs)
496
+ end
497
+
498
+ def self.brick_pluck(*args, withhold_ids: true, **kwargs)
499
+ all.brick_pluck(*args, withhold_ids: withhold_ids, **kwargs)
505
500
  end
506
501
 
507
502
  def self.brick_where(*args)
@@ -559,7 +554,7 @@ module ActiveRecord
559
554
  # If it's a CollectionProxy (which inherits from Relation) then need to dig
560
555
  # out the core Relation object which is found in the association scope.
561
556
  brick_rel = is_a?(ActiveRecord::Associations::CollectionProxy) ? scope : self
562
- brick_rel = brick_rel.dup if do_dup
557
+ brick_rel = (@_brick_rel_dup ||= brick_rel.dup) if do_dup
563
558
  # Start out with a hash that has only the root table name
564
559
  brick_rel.instance_variable_set(:@_brick_links, bl = { '' => table_name })
565
560
  brick_rel.arel.ast if do_dup # Walk the AST tree in order to capture all the other correlation names
@@ -567,10 +562,22 @@ module ActiveRecord
567
562
  end
568
563
  end
569
564
 
570
- def brick_select(*args, params: {}, order_by: nil, translations: {},
571
- join_array: ::Brick::JoinArray.new,
572
- cust_col_override: nil,
573
- brick_col_names: true)
565
+ def brick_select(*args, **kwargs)
566
+ selects = args[0].is_a?(Array) ? args[0] : args
567
+ _brick_querying(selects, **kwargs)
568
+ select(selects)
569
+ end
570
+
571
+ def brick_pluck(*args, withhold_ids: true, **kwargs)
572
+ selects = args[0].is_a?(Array) ? args[0] : args
573
+ _brick_querying(selects, withhold_ids: withhold_ids, **kwargs)
574
+ pluck(selects)
575
+ end
576
+
577
+ def _brick_querying(*args, withhold_ids: nil, params: {}, order_by: nil, translations: {},
578
+ join_array: ::Brick::JoinArray.new,
579
+ cust_col_override: nil,
580
+ brick_col_names: nil)
574
581
  selects = args[0].is_a?(Array) ? args[0] : args
575
582
  if selects.present? && cust_col_override.nil? # See if there's any fancy ones in the select list
576
583
  idx = 0
@@ -654,13 +661,13 @@ module ActiveRecord
654
661
  "'<#{typ.end_with?('_TYP') ? typ[0..-5] : typ}>' AS #{col.name}"
655
662
  end
656
663
  end
657
- else # Having some select columns chosen, add any missing always_load_fields for this model ...
664
+ elsif !withhold_ids # Having some select columns chosen, add any missing always_load_fields for this model ...
658
665
  this_model = klass
659
666
  loop do
660
667
  ::Brick.config.always_load_fields.fetch(this_model.name, nil)&.each do |alf|
661
668
  selects << alf unless selects.include?(alf)
662
669
  end
663
- # ... plus any and all STI superclasses it may inherit from
670
+ # ... plus ALF fields from any and all STI superclasses it may inherit from
664
671
  break if (this_model = this_model.superclass).abstract_class? || this_model == ActiveRecord::Base
665
672
  end
666
673
  end
@@ -673,15 +680,16 @@ module ActiveRecord
673
680
  end
674
681
  end
675
682
 
676
- core_selects = selects.dup
683
+ # core_selects = selects.dup
677
684
  id_for_tables = Hash.new { |h, k| h[k] = [] }
678
685
  field_tbl_names = Hash.new { |h, k| h[k] = {} }
679
686
  used_col_aliases = {} # Used to make sure there is not a name clash
680
687
 
681
688
  # CUSTOM COLUMNS
682
689
  # ==============
683
- (cust_col_override || klass._br_cust_cols).each do |k, cc|
684
- if respond_to?(k) # Name already taken?
690
+ (cust_col_override || (!withhold_ids && klass._br_cust_cols))&.each do |k, cc|
691
+ brick_links # Intentionally create a relation duplicate
692
+ if @_brick_rel_dup.respond_to?(k) # Name already taken?
685
693
  # %%% Use ensure_unique here in this kind of fashion:
686
694
  # cnstr_name = ensure_unique(+"(brick) #{for_tbl}_#{pri_tbl}", nil, bts, hms)
687
695
  # binding.pry
@@ -730,12 +738,14 @@ module ActiveRecord
730
738
  selects << "#{_br_quoted_name(tbl_name)}.#{_br_quoted_name(cc_part.last)} AS #{_br_quoted_name(col_alias)}"
731
739
  cc_part << col_alias
732
740
  end
733
- # Add a key column unless we've already got it
734
- if key_alias && !used_col_aliases.key?(key_alias)
735
- selects << "#{_br_quoted_name(key_tbl_name)}.#{_br_quoted_name(dest_pk)} AS #{_br_quoted_name(key_alias)}"
736
- used_col_aliases[key_alias] = nil
741
+ unless withhold_ids
742
+ # Add a key column unless we've already got it
743
+ if key_alias && !used_col_aliases.key?(key_alias)
744
+ selects << "#{_br_quoted_name(key_tbl_name)}.#{_br_quoted_name(dest_pk)} AS #{_br_quoted_name(key_alias)}"
745
+ used_col_aliases[key_alias] = nil
746
+ end
747
+ cc[2] = key_alias ? [key_klass, key_alias] : nil
737
748
  end
738
- cc[2] = key_alias ? [key_klass, key_alias] : nil
739
749
  end
740
750
 
741
751
  # LEFT OUTER JOINs
@@ -751,7 +761,7 @@ module ActiveRecord
751
761
  # %%% Strangely in Rails 7.1 on a slower system then very rarely brick_link comes back nil...
752
762
  brick_link = brick_links[sel_col.first]
753
763
  field_tbl_name = brick_link&.split('.')&.last ||
754
- # ... so here's a best-effort guess for what the table name might be.
764
+ # ... so if it is nil then here's a best-effort guess as to what the table name might be.
755
765
  klass.reflect_on_association(sel_col.first)&.klass&.table_name
756
766
  # If it's Oracle, quote any AREL aliases that had been applied
757
767
  field_tbl_name = "\"#{field_tbl_name}\"" if ::Brick.is_oracle && brick_links.values.include?(field_tbl_name)
@@ -1022,9 +1032,10 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
1022
1032
  selects << 'customer_id' if klass.name == 'Pay::Subscription' && Pay::Subscription.columns_hash.key?('customer_id')
1023
1033
 
1024
1034
  pieces, my_dsl = klass.brick_parse_dsl(join_array = ::Brick::JoinArray.new, [], translations = {}, false, nil, true)
1025
- brick_select(
1035
+ _brick_querying(
1026
1036
  selects, where_values_hash, nil, translations: translations, join_array: join_array,
1027
- cust_col_override: { '_br' => (descrip_cols = [pieces, my_dsl]) }
1037
+ cust_col_override: { '_br' => (descrip_cols = [pieces, my_dsl]) },
1038
+ brick_col_names: true
1028
1039
  )
1029
1040
  order_values = "#{_br_quoted_name(klass.table_name)}.#{_br_quoted_name(klass.primary_key)}"
1030
1041
  [self.select(selects), descrip_cols]
@@ -2246,9 +2257,10 @@ class Object
2246
2257
 
2247
2258
  ar_relation = ActiveRecord.version < Gem::Version.new('4') ? real_model.preload : real_model.all
2248
2259
  params['_brick_is_api'] = true if (is_api = request.format == :js || current_api_root)
2249
- @_brick_params = ar_relation.brick_select((selects ||= []), params: params, order_by: order_by,
2250
- translations: (translations = {}),
2251
- join_array: (join_array = ::Brick::JoinArray.new))
2260
+ @_brick_params = ar_relation._brick_querying((selects ||= []), params: params, order_by: order_by,
2261
+ translations: (translations = {}),
2262
+ join_array: (join_array = ::Brick::JoinArray.new),
2263
+ brick_col_names: true)
2252
2264
 
2253
2265
  if is_api # Asking for JSON?
2254
2266
  # Apply column renaming
@@ -2342,7 +2354,7 @@ class Object
2342
2354
  _, order_by_txt = model._brick_calculate_ordering(default_ordering(table_name, pk, true)) if pk
2343
2355
  code << " def index\n"
2344
2356
  code << " @#{plural_table_name} = #{model.name}#{pk&.present? ? ".order(#{order_by_txt.join(', ')})" : '.all'}\n"
2345
- code << " @#{plural_table_name}.brick_select(params)\n"
2357
+ code << " @#{plural_table_name}._brick_querying(params, brick_col_names: true)\n"
2346
2358
  code << " end\n"
2347
2359
 
2348
2360
  is_pk_string = nil
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 209
8
+ TINY = 210
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
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.209
4
+ version: 1.0.210
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-03-20 00:00:00.000000000 Z
11
+ date: 2024-03-22 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.2.33
288
+ rubygems_version: 3.1.6
289
289
  signing_key:
290
290
  specification_version: 4
291
291
  summary: Create a Rails app from data alone