brick 1.0.98 → 1.0.100

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: d4285ef6fb81d75bd90ceffc7d66c7fa096f04fb998da590f291f28fc9dfb45d
4
- data.tar.gz: 2d031b156fd9c82d19af9b7818387eaecdd8cfadf939cbcf3b3b479474a77b54
3
+ metadata.gz: ba0de7f332d1d98502a4e66bc4fda9b44d4f97fe6d6a259ac7527a856c726000
4
+ data.tar.gz: 45898a638f4c944cf33e98ff73a41da97686819bbdfcc8534257c013a6b28582
5
5
  SHA512:
6
- metadata.gz: 5967ede119f86cd92f88abb0f43bd2049eda4272c14ae7fa1c3f9ecc54c813c4c227be2d99aaa501363e42ef34a3eb5d0a0924ac4e540ab668e40a9a9d28311e
7
- data.tar.gz: ab01005e485b9335c67ba48bb01a13db78fed3ce31293122fae8fbf1317b3bc0c3197adb087ec4b125e2ff7153e52fb55d8b7fc675b1e7759233cf8d42769ac7
6
+ metadata.gz: 28079c58b020d395845c681710c88db3e7a32ae312fbdf607ab496854aab37d29f3a9dfed78a2495a011b3817aed8259260a1d0d5ecd409803d89b4eda70b87f
7
+ data.tar.gz: 834499603e05412ee19c2f5db90f55df1f927eff85a41488e4f57381065580aeb4477700596988e4cc630282268f40045d1831822bde2c80b659a23e257f692a
@@ -398,7 +398,7 @@ module ActiveRecord
398
398
  # Links from ActiveRecord association pathing names over to real table correlation names
399
399
  # that get chosen when the AREL AST tree is walked.
400
400
  def brick_links
401
- @brick_links ||= {}
401
+ @brick_links ||= { '' => table_name }
402
402
  end
403
403
 
404
404
  def brick_select(params, selects = [], order_by = nil, translations = {}, join_array = ::Brick::JoinArray.new)
@@ -436,6 +436,7 @@ module ActiveRecord
436
436
 
437
437
  # %%% Skip the metadata columns
438
438
  if selects.empty? # Default to all columns
439
+ id_parts = (id_col = klass.primary_key).is_a?(Array) ? id_col : [id_col]
439
440
  tbl_no_schema = table.name.split('.').last
440
441
  # %%% Have once gotten this error with MSSQL referring to http://localhost:3000/warehouse/cold_room_temperatures__archive
441
442
  # ActiveRecord::StatementInvalid (TinyTds::Error: DBPROCESS is dead or not enabled)
@@ -496,16 +497,23 @@ module ActiveRecord
496
497
  dest_pk = nil
497
498
  key_alias = nil
498
499
  cc.first.each do |cc_part|
499
- dest_klass = cc_part[0..-2].inject(klass) { |kl, cc_part_term| kl.reflect_on_association(cc_part_term).klass }
500
+ dest_klass = cc_part[0..-2].inject(klass) do |kl, cc_part_term|
501
+ # %%% Clear column info properly so we can do multiple subsequent requests
502
+ # binding.pry unless kl.reflect_on_association(cc_part_term)
503
+ kl.reflect_on_association(cc_part_term)&.klass || klass
504
+ end
500
505
  tbl_name = rel_dupe.brick_links[cc_part[0..-2].map(&:to_s).join('.')]
501
506
  # Deal with the conflict if there are two parts in the custom column named the same,
502
507
  # "category.name" and "product.name" for instance will end up with aliases of "name"
503
508
  # and "product__name".
504
- cc_part_idx = cc_part.length - 1
505
- while cc_part_idx > 0 &&
506
- (col_alias = "br_cc_#{k}__#{cc_part[cc_part_idx..-1].map(&:to_s).join('__')}") &&
507
- used_col_aliases.key?(col_alias)
508
- cc_part_idx -= 1
509
+ if (cc_part_idx = cc_part.length - 1).zero?
510
+ col_alias = "br_cc_#{k}__#{table_name.tr('.', '_')}"
511
+ else
512
+ while cc_part_idx > 0 &&
513
+ (col_alias = "br_cc_#{k}__#{cc_part[cc_part_idx..-1].map(&:to_s).join('__').tr('.', '_')}") &&
514
+ used_col_aliases.key?(col_alias)
515
+ cc_part_idx -= 1
516
+ end
509
517
  end
510
518
  used_col_aliases[col_alias] = nil
511
519
  # Set up custom column links by preparing key_klass and key_alias
@@ -963,7 +971,7 @@ Module.class_exec do
963
971
  ::Brick.is_oracle ? class_name.upcase : class_name,
964
972
  (plural_class_name = class_name.pluralize)].find { |s| Brick.db_schemas&.include?(s) }&.camelize ||
965
973
  (::Brick.config.sti_namespace_prefixes&.key?("::#{class_name}::") && class_name) ||
966
- (::Brick.config.table_name_prefixes&.values.include?(class_name) && class_name))
974
+ (::Brick.config.table_name_prefixes.values.include?(class_name) && class_name))
967
975
  return self.const_get(schema_name) if self.const_defined?(schema_name)
968
976
 
969
977
  # Build out a module for the schema if it's namespaced
@@ -1372,7 +1380,7 @@ class Object
1372
1380
  when Symbol
1373
1381
  order_tbl[order_default] || order_default
1374
1382
  else
1375
- pk.map(&:to_sym) # If it's not a custom ORDER BY, just use the key
1383
+ pk.map { |part| "#{table_name}.#{part}"}.join(', ') # If it's not a custom ORDER BY, just use the key
1376
1384
  end
1377
1385
  end
1378
1386
 
@@ -1568,7 +1576,8 @@ class Object
1568
1576
  order_by, _ = model._brick_calculate_ordering(ordering, true) # Don't do the txt part
1569
1577
 
1570
1578
  ar_relation = ActiveRecord.version < Gem::Version.new('4') ? model.preload : model.all
1571
- @_brick_params = ar_relation.brick_select(params, (selects = []), order_by,
1579
+
1580
+ @_brick_params = ar_relation.brick_select(params, (selects ||= []), order_by,
1572
1581
  translations = {},
1573
1582
  join_array = ::Brick::JoinArray.new)
1574
1583
  # %%% Add custom HM count columns
@@ -54,7 +54,7 @@ module Brick
54
54
  end
55
55
 
56
56
  # When table names have specific prefixes, automatically place them in their own module with a table_name_prefix.
57
- ::Brick.table_name_prefixes = app.config.brick.fetch(:table_name_prefixes, [])
57
+ ::Brick.table_name_prefixes = app.config.brick.fetch(:table_name_prefixes, {})
58
58
 
59
59
  # Columns to treat as being metadata for purposes of identifying associative tables for has_many :through
60
60
  ::Brick.metadata_columns = app.config.brick.fetch(:metadata_columns, ['created_at', 'updated_at', 'deleted_at'])
@@ -11,7 +11,7 @@ module Brick::Rails::FormTags
11
11
  out << "<th x-order=\"#{pk.join(',')}\"></th>"
12
12
  end
13
13
 
14
- col_keys = relation.columns.each_with_object([]) do |col, s|
14
+ col_keys ||= relation.columns.each_with_object([]) do |col, s|
15
15
  col_name = col.name
16
16
  next if inclusions&.exclude?(col_name) ||
17
17
  (pk.include?(col_name) && [:integer, :uuid].include?(col.type) && !bts.key?(col_name)) ||
@@ -122,7 +122,7 @@ module Brick::Rails::FormTags
122
122
  if (link_id = obj.send(cust_col.last[1]) if cust_col.last)
123
123
  out << link_to(cust_txt, send("#{cust_col.last.first._brick_index(:singular)}_path", link_id))
124
124
  else
125
- out << cust_txt
125
+ out << (cust_txt || '')
126
126
  end
127
127
  else # Bad column name!
128
128
  out << '?'
@@ -186,13 +186,14 @@ module Brick::Rails::FormTags
186
186
  end
187
187
  end
188
188
  filter = "?#{filter_parts.join('&')}" if filter_parts.present?
189
+ app_routes = Rails.application.routes # In case we're operating in another engine, reference the application since Brick routes are placed there.
189
190
  if (klass_or_obj&.is_a?(Class) && klass_or_obj < ActiveRecord::Base) ||
190
191
  (klass_or_obj&.is_a?(ActiveRecord::Base) && klass_or_obj.new_record? && (klass_or_obj = klass_or_obj.class))
191
- path = (proc = kwargs[:index_proc]) ? proc.call(klass_or_obj) : "#{send("#{klass_or_obj.base_class._brick_index}_path")}#{filter}"
192
+ path = (proc = kwargs[:index_proc]) ? proc.call(klass_or_obj) : "#{app_routes.path_for(controller: klass_or_obj.base_class._brick_index, action: :index)}#{filter}"
192
193
  lt_args = [text || "Index for #{klass_or_obj.name.pluralize}", path]
193
194
  else
194
195
  # If there are multiple incoming parameters then last one is probably the actual ID, and first few might be some nested tree of stuff leading up to it
195
- path = (proc = kwargs[:show_proc]) ? proc.call(klass_or_obj) : "#{send("#{klass_or_obj.class.base_class._brick_index(:singular)}_path", klass_or_obj)}#{filter}"
196
+ path = (proc = kwargs[:show_proc]) ? proc.call(klass_or_obj) : "#{app_routes.path_for(controller: klass_or_obj.class.base_class._brick_index, action: :show, id: klass_or_obj)}#{filter}"
196
197
  lt_args = [text || "Show this #{klass_or_obj.class.name}", path]
197
198
  end
198
199
  link_to(*lt_args, **kwargs)
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 98
8
+ TINY = 100
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.98
4
+ version: 1.0.100
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-04 00:00:00.000000000 Z
11
+ date: 2022-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord