brick 1.0.212 → 1.0.213

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: 3e954e525ea7a17eea2b33a125283f8af47a7bad1e457780815a8f53e06ed8fc
4
- data.tar.gz: 9ded8bfa75d407294eb3e34895d1fc36ffa17767b9cbdeee0c961d6d9e821653
3
+ metadata.gz: 02a0436d0c71a40e1aa3858e4fdf20822f32b02864e621964bce288b8b21ad60
4
+ data.tar.gz: 8257218e3c1e9c26842753590e627802842c67dec93891aec7139fd2f31d67c0
5
5
  SHA512:
6
- metadata.gz: 6c2d33f2a6247cc001071929731d2b2543d2b91ba0e8c22afeda7d9fa40e37ae9c3957d4046f8157a34b1549dca8e542de97a58f22b25a312532eed775d3989c
7
- data.tar.gz: 4e63b7986eb7b683421ef92d00fe61a3970ed0d24fb57403a89d05c114760ad00310e6c635d66bc0388e5ca26b6c6fd2061574c83e1f70b60f90baa22babcb92
6
+ metadata.gz: 222b736da74b699a1f352ffff9f087f39048fceaf995dc28733823b4d38271c0bc04ecba506fb6fd027a7f39883009baede3d9c70f81a46dc023f692d6c831e4
7
+ data.tar.gz: bdee88e65dad07aa66b6ce9458a44ba8d1ad069b937d5bceae65f020162107336b6d7619aee03ed4c56c25a3e38b4c17ce0352677883426802dfe28ac3c8567a
data/lib/brick/config.rb CHANGED
@@ -429,6 +429,19 @@ module Brick
429
429
  end
430
430
  end
431
431
 
432
+ def acts_as_list_cols
433
+ @mutex.synchronize { @acts_as_list || {} }
434
+ end
435
+
436
+ # Get something like:
437
+ # { 'on_call_list' => { _brick_default: [:last_name, :first_name] } }
438
+ # { 'on_call_list' => { _brick_default: :sequence } }
439
+ def acts_as_list_cols=(position_cols)
440
+ @mutex.synchronize do
441
+ @acts_as_list ||= position_cols
442
+ end
443
+ end
444
+
432
445
  def metadata_columns
433
446
  @mutex.synchronize { @metadata_columns ||= ['created_at', 'updated_at', 'deleted_at'] }
434
447
  end
@@ -196,6 +196,33 @@ module ActiveRecord
196
196
  def _brick_monetized_attributes
197
197
  @_brick_monetized_attributes ||= respond_to?(:monetized_attributes) ? monetized_attributes.values : {}
198
198
  end
199
+
200
+ # def acts_as_list(aal_cols = nil)
201
+ # if aal_cols
202
+ # aal_cols = [aal_cols] unless aal_cols.is_a?(Array)
203
+ # @acts_as_list_cols = aal_cols.each_with_object([]) do |aal_col, s|
204
+ # if column_names.include?(aal_col = aal_col.to_s) && !s.include?(aal_col)
205
+ # s << aal_col
206
+ # end
207
+ # end
208
+ # else
209
+ # if [:integer, :bigint].include?(columns_hash['position']&.type)
210
+ # @acts_as_list_cols = ['position']
211
+ # else
212
+ # return
213
+ # end
214
+ # end
215
+ # # Override save in order to update neighbours when necessary
216
+ # alias _brick_save save
217
+ # def save
218
+ # # @acts_as_list_cols
219
+ # # -1
220
+ # @acts_as_list_cols.each do |aal_col|
221
+ # binding.pry if (aal_change = changes[aal_col])
222
+ # end
223
+ # _brick_save
224
+ # end
225
+ # end
199
226
  end
200
227
 
201
228
  def self.brick_parse_dsl(join_array = nil, prefix = [], translations = {}, is_polymorphic = false, dsl = nil, emit_dsl = false)
@@ -230,11 +257,7 @@ module ActiveRecord
230
257
  end
231
258
  if first_parts
232
259
  if (parts = prefix + first_parts + [parts[-1]]).length > 1 && klass
233
- unless is_polymorphic
234
- s = join_array
235
- parts[0..-3].each { |v| s = s[v.to_sym] }
236
- s[parts[-2]] = nil # unless parts[-2].empty? # Using []= will "hydrate" any missing part(s) in our whole series
237
- end
260
+ join_array.add_parts(parts) unless is_polymorphic
238
261
  translations[parts[0..-2].join('.')] = klass
239
262
  end
240
263
  if klass&.column_names.exclude?(parts.last) &&
@@ -538,7 +561,11 @@ module ActiveRecord
538
561
  end
539
562
 
540
563
  def self.brick_where(*args)
541
- (relation = all).brick_where(*args)
564
+ all.brick_where(*args)
565
+ end
566
+
567
+ def self.brick_group(*args, withhold_ids: true, **kwargs)
568
+ all.brick_group(*args, withhold_ids: withhold_ids, **kwargs)
542
569
  end
543
570
 
544
571
  private
@@ -612,27 +639,36 @@ module ActiveRecord
612
639
  pluck(selects)
613
640
  end
614
641
 
615
- def _brick_querying(*args, withhold_ids: nil, params: {}, order_by: nil, translations: {},
642
+ def brick_group(*args, **kwargs)
643
+ grouping = args[0].is_a?(Array) ? args[0] : args
644
+ _brick_querying(select_values.frozen? ? select_values.dup : select_values,
645
+ grouping: grouping, **kwargs)
646
+ self
647
+ end
648
+
649
+ def _brick_querying(*args, grouping: nil, withhold_ids: nil, params: {}, order_by: nil, translations: {},
616
650
  join_array: ::Brick::JoinArray.new,
617
651
  cust_col_override: nil,
618
652
  brick_col_names: nil)
619
653
  selects = args[0].is_a?(Array) ? args[0] : args
620
- if selects.present? && cust_col_override.nil? # See if there's any fancy ones in the select list
621
- idx = 0
622
- while idx < selects.length
623
- v = selects[idx]
624
- if v.is_a?(String) && v.index('.')
625
- # No prefixes and not polymorphic
626
- pieces = self.brick_parse_dsl(join_array, [], translations, false, dsl = "[#{v}]")
627
- (cust_col_override ||= {})[v.tr('.', '_').to_sym] = [pieces, dsl, true]
628
- selects.delete_at(idx)
629
- else
630
- idx += 1
654
+ unless cust_col_override
655
+ if selects.present? # See if there's any fancy ones in the select list
656
+ idx = 0
657
+ while idx < selects.length
658
+ v = selects[idx]
659
+ if v.is_a?(String) && v.index('.')
660
+ # No prefixes and not polymorphic
661
+ pieces = self.brick_parse_dsl(join_array, [], translations, false, dsl = "[#{v}]")
662
+ (cust_col_override ||= {})[v.tr('.', '_').to_sym] = [pieces, dsl, true]
663
+ selects.delete_at(idx)
664
+ else
665
+ idx += 1
666
+ end
631
667
  end
668
+ elsif selects.is_a?(Hash) && params.empty? # Make sense of things if they've passed in only params
669
+ params = selects
670
+ selects = []
632
671
  end
633
- elsif selects.is_a?(Hash) && params.empty? && cust_col_override.nil? # Make sense of things if they've passed in only params
634
- params = selects
635
- selects = []
636
672
  end
637
673
  is_add_bts = is_add_hms = !cust_col_override
638
674
 
@@ -710,6 +746,14 @@ module ActiveRecord
710
746
  end
711
747
  end
712
748
 
749
+ # Establish necessary JOINs for any custom GROUP BY columns
750
+ grouping&.each do |group_item|
751
+ # JOIN in all the same ways as the pathing describes
752
+ if group_item.is_a?(String) && (ref_parts = group_item.split('.')).length > 1
753
+ join_array.add_parts(ref_parts)
754
+ end
755
+ end
756
+
713
757
  if join_array.present?
714
758
  if ActiveRecord.version < Gem::Version.new('4.2')
715
759
  self.joins_values += join_array # Same as: joins!(join_array)
@@ -725,7 +769,9 @@ module ActiveRecord
725
769
 
726
770
  # CUSTOM COLUMNS
727
771
  # ==============
728
- (cust_col_override || (!withhold_ids && klass._br_cust_cols))&.each do |k, cc|
772
+ cust_cols = cust_col_override
773
+ cust_cols ||= klass._br_cust_cols unless withhold_ids
774
+ cust_cols&.each do |k, cc|
729
775
  brick_links # Intentionally create a relation duplicate
730
776
  if @_brick_rel_dup.respond_to?(k) # Name already taken?
731
777
  # %%% Use ensure_unique here in this kind of fashion:
@@ -753,7 +799,7 @@ module ActiveRecord
753
799
  col_alias = "#{col_prefix}#{k}__#{table_name.tr('.', '_')}_#{cc_part.first}"
754
800
  elsif brick_col_names ||
755
801
  used_col_aliases.key?(col_alias = k.to_s) # This sets a simpler custom column name if possible
756
- while cc_part_idx > 0 &&
802
+ while cc_part_idx >= 0 &&
757
803
  (col_alias = "#{col_prefix}#{k}__#{cc_part[cc_part_idx..-1].map(&:to_s).join('__').tr('.', '_')}") &&
758
804
  used_col_aliases.key?(col_alias)
759
805
  cc_part_idx -= 1
@@ -988,6 +1034,20 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
988
1034
  klass._br_hm_counts.delete(n)
989
1035
  end
990
1036
 
1037
+ # Rewrite the group values to reference table and correlation names built out by AREL
1038
+ if grouping
1039
+ group2 = (gvgu = (group_values + grouping).uniq).each_with_object([]) do |v, s|
1040
+ if v.is_a?(Symbol) || (v_parts = v.split('.')).length == 1
1041
+ s << v
1042
+ elsif (tbl_name = brick_links[v_parts[0..-2].join('.')]&.split('.')&.last)
1043
+ s << "#{tbl_name}.#{v_parts.last}"
1044
+ else
1045
+ s << v
1046
+ end
1047
+ end
1048
+ group!(*group2)
1049
+ end
1050
+
991
1051
  unless wheres.empty?
992
1052
  # Rewrite the wheres to reference table and correlation names built out by AREL
993
1053
  where_nots = {}
@@ -998,7 +1058,7 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
998
1058
  if (v_parts = v.first.split('.')).length == 1
999
1059
  (is_not ? where_nots : s)[v.first] = v.last
1000
1060
  else
1001
- tbl_name = brick_links[v_parts.first].split('.').last
1061
+ tbl_name = brick_links[v_parts[0..-2].join('.')].split('.').last
1002
1062
  (is_not ? where_nots : s)["#{tbl_name}.#{v_parts.last}"] = v.last
1003
1063
  end
1004
1064
  end
@@ -1095,13 +1155,9 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
1095
1155
  # && joins_values.empty? # Make sure we don't step on any toes if they've already specified JOIN things
1096
1156
  ja = nil
1097
1157
  opts.each do |k, v|
1158
+ # JOIN in all the same ways as the pathing describes
1098
1159
  if k.is_a?(String) && (ref_parts = k.split('.')).length > 1
1099
- # JOIN in all the same ways as the pathing describes
1100
- linkage = (ja ||= ::Brick::JoinArray.new)
1101
- ref_parts[0..-3].each do |prefix_part|
1102
- linkage = linkage[prefix_part.to_sym]
1103
- end
1104
- linkage[ref_parts[-2].to_sym] = nil
1160
+ (ja ||= ::Brick::JoinArray.new).add_parts(ref_parts)
1105
1161
  end
1106
1162
  end
1107
1163
  if ja&.present?
@@ -1846,6 +1902,12 @@ class Object
1846
1902
  end
1847
1903
  end
1848
1904
 
1905
+ # Apply any acts_as_list things
1906
+ if (aal_col = ::Brick.config.acts_as_list_cols.fetch(matching, nil))
1907
+ new_model_class.send(:acts_as_list, aal_col.to_sym)
1908
+ code << " acts_as_list :#{aal_col}\n"
1909
+ end
1910
+
1849
1911
  # Auto-support Ransack if it's present
1850
1912
  if self.respond_to?(:ransackable_attributes)
1851
1913
  def self.ransackable_attributes(auth_object = nil)
@@ -173,7 +173,6 @@ erDiagram
173
173
  <%= erd_sidelinks(shown_classes, hm_class).html_safe %>
174
174
  <% end
175
175
  def dt_lookup(dt)
176
- puts dt.inspect
177
176
  { 'integer' => 'int', 'character varying' => 'varchar', 'double precision' => 'float',
178
177
  'timestamp without time zone' => 'timestamp',
179
178
  'timestamp with time zone' => 'timestamp',
@@ -165,6 +165,12 @@ module Brick
165
165
  end.tap { |member| push(member) }
166
166
  end
167
167
  end
168
+
169
+ def add_parts(parts)
170
+ s = self
171
+ parts[0..-3].each { |part| s = s[part.to_sym] }
172
+ s[parts[-2].to_sym] = nil # unless parts[-2].empty? # Using []= will "hydrate" any missing part(s) in our whole series
173
+ end
168
174
  end
169
175
 
170
176
  class JoinHash < Hash
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 212
8
+ TINY = 213
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
@@ -53,7 +53,12 @@ module Brick
53
53
  s[v_parts.first] = nil unless [::Brick.default_schema, 'public'].include?(v_parts.first)
54
54
  end
55
55
  end
56
- seeds = +"# Seeds file for #{ActiveRecord::Base.connection.current_database}:\n"
56
+ seeds = +'# Seeds file for '
57
+ if (arbc = ActiveRecord::Base.connection).respond_to?(:current_database) # SQLite3 can't do this!
58
+ seeds << "#{arbc.current_database}:\n"
59
+ elsif (filename = arbc.instance_variable_get(:@connection_parameters)&.fetch(:database, nil))
60
+ seeds << "#{filename}:\n"
61
+ end
57
62
  done = []
58
63
  fks = {}
59
64
  stuck = {}
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.212
4
+ version: 1.0.213
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-28 00:00:00.000000000 Z
11
+ date: 2024-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord