brick 1.0.140 → 1.0.141
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 +4 -4
- data/lib/brick/config.rb +1 -1
- data/lib/brick/extensions.rb +36 -13
- data/lib/brick/frameworks/rails/engine.rb +2 -2
- data/lib/brick/version_number.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f2d0e5e8ee3fb56acdbdee808b2a6ebe8cbf8b43457fd10b46f6197d82ef054
|
4
|
+
data.tar.gz: f21cca0ba332706e77d7f21245aeef6aa922668fbd41020e4edecd6672fdf4e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2a88167018d956d7066eaae2bb0fa05e69a1efe751b725477a6b13ad575fad7e89237fc1749138533723103f1a63018a23f6ba83cb1b6bed972e22c3bb89321
|
7
|
+
data.tar.gz: a6fc5f155686488fac49aea2eb58bc734021ea2be01fd505acbe29c357f888f65b17ebea78bae4c22ce83e4847eaef456c8a5329193753b8ac756a724d998ed1
|
data/lib/brick/config.rb
CHANGED
data/lib/brick/extensions.rb
CHANGED
@@ -296,7 +296,7 @@ module ActiveRecord
|
|
296
296
|
|
297
297
|
# Providing a relation object allows auto-modules built from table name prefixes to work
|
298
298
|
def self._brick_index(mode = nil, separator = '_', relation = nil)
|
299
|
-
return if abstract_class
|
299
|
+
return if abstract_class?
|
300
300
|
|
301
301
|
tbl_parts = ((mode == :singular) ? table_name.singularize : table_name).split('.')
|
302
302
|
tbl_parts.shift if ::Brick.apartment_multitenant && tbl_parts.length > 1 && tbl_parts.first == ::Brick.apartment_default_tenant
|
@@ -574,9 +574,14 @@ module ActiveRecord
|
|
574
574
|
"'<#{typ.end_with?('_TYP') ? typ[0..-5] : typ}>' AS #{col.name}"
|
575
575
|
end
|
576
576
|
end
|
577
|
-
else # Having some select columns chosen, add any missing always_load_fields for this model
|
578
|
-
|
579
|
-
|
577
|
+
else # Having some select columns chosen, add any missing always_load_fields for this model ...
|
578
|
+
this_model = klass
|
579
|
+
loop do
|
580
|
+
::Brick.config.always_load_fields.fetch(this_model.name, nil)&.each do |alf|
|
581
|
+
selects << alf unless selects.include?(alf)
|
582
|
+
end
|
583
|
+
# ... plus any and all STI superclasses it may inherit from
|
584
|
+
break if (this_model = this_model.superclass).abstract_class? || this_model == ActiveRecord::Base
|
580
585
|
end
|
581
586
|
end
|
582
587
|
|
@@ -637,7 +642,8 @@ module ActiveRecord
|
|
637
642
|
col_prefix = 'br_cc_' if brick_col_names
|
638
643
|
if (cc_part_idx = cc_part.length - 1).zero?
|
639
644
|
col_alias = "#{col_prefix}#{k}__#{table_name.tr('.', '_')}_#{cc_part.first}"
|
640
|
-
|
645
|
+
elsif brick_col_names ||
|
646
|
+
used_col_aliases.key?(col_alias = k.to_s) # This sets a simpler custom column name if possible
|
641
647
|
while cc_part_idx > 0 &&
|
642
648
|
(col_alias = "#{col_prefix}#{k}__#{cc_part[cc_part_idx..-1].map(&:to_s).join('__').tr('.', '_')}") &&
|
643
649
|
used_col_aliases.key?(col_alias)
|
@@ -965,19 +971,36 @@ JOIN (SELECT #{hm_selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', '
|
|
965
971
|
[self.select(selects), descrip_cols]
|
966
972
|
end
|
967
973
|
|
968
|
-
|
974
|
+
# Accommodate when a relation gets queried for a model, and in that model it has an #after_initialize block
|
975
|
+
# which references attributes that were not originally included as part of the select_values.
|
976
|
+
def brick_(method, *args, brick_orig_relation: nil, **kwargs, &block)
|
969
977
|
begin
|
970
|
-
uniq
|
978
|
+
send(method, *args, **kwargs, &block) # method will be something like :uniq or :each
|
971
979
|
rescue ActiveModel::MissingAttributeError => e
|
972
|
-
# If this model has an #after_initialize then it might try to reference attributes we haven't brought in
|
973
980
|
if (err_msg = e.message).start_with?('missing attribute: ') &&
|
974
981
|
klass.column_names.include?(col_name = e.message[19..-1])
|
975
982
|
(dup_rel = dup).select_values << col_name
|
976
|
-
ret = dup_rel.
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
983
|
+
ret = dup_rel.brick_(method, *args, brick_orig_relation: (brick_orig_relation ||= self), **kwargs, &block)
|
984
|
+
always_loads = (::Brick.config.always_load_fields ||= {})
|
985
|
+
|
986
|
+
# Find the most parent STI superclass for this model, and apply an always_load_fields entry for this missing column
|
987
|
+
has_field = false
|
988
|
+
this_model = klass
|
989
|
+
loop do
|
990
|
+
has_field = true if always_loads.key?(this_model.name) && always_loads[this_model.name]&.include?(col_name)
|
991
|
+
break if has_field || (next_model = this_model.superclass).abstract_class? || next_model == ActiveRecord::Base
|
992
|
+
this_model = next_model
|
993
|
+
end
|
994
|
+
unless has_field
|
995
|
+
(brick_orig_relation || self).instance_variable_set(:@brick_new_alf, ((always_loads[this_model.name] ||= []) << col_name))
|
996
|
+
end
|
997
|
+
|
998
|
+
if self.object_id == brick_orig_relation.object_id
|
999
|
+
puts "*** WARNING: Missing field#{'s' if @brick_new_alf.length > 1}!
|
1000
|
+
Might want to add this in your brick.rb:
|
1001
|
+
::Brick.always_load_fields = { #{klass.name.inspect} => #{@brick_new_alf.inspect} }"
|
1002
|
+
remove_instance_variable(:@brick_new_alf)
|
1003
|
+
end
|
981
1004
|
ret
|
982
1005
|
else
|
983
1006
|
[]
|
@@ -1649,7 +1649,7 @@ end
|
|
1649
1649
|
bt << (option_detail = [[\"(No #\{bt_name\} chosen)\", '^^^brick_NULL^^^']])
|
1650
1650
|
# %%% Accommodate composite keys for obj.pk at the end here
|
1651
1651
|
collection, descrip_cols = bt_class&.order(Arel.sql(\"#\{bt_class.table_name}.#\{obj_pk = bt_class.primary_key}\"))&.brick_list
|
1652
|
-
collection&.each do |obj|
|
1652
|
+
collection&.brick_(:each) do |obj|
|
1653
1653
|
option_detail << [
|
1654
1654
|
obj.brick_descrip(
|
1655
1655
|
descrip_cols&.first&.map { |col| obj.send(col.last) },
|
@@ -1729,7 +1729,7 @@ end
|
|
1729
1729
|
else # We get an array back when AR < 4.2
|
1730
1730
|
collection2 = collection.to_a.compact
|
1731
1731
|
end
|
1732
|
-
collection2 = collection2.
|
1732
|
+
collection2 = collection2.brick_(:uniq)
|
1733
1733
|
if collection2.empty? %>
|
1734
1734
|
<tr><td>(none)</td></tr>
|
1735
1735
|
<% else
|
data/lib/brick/version_number.rb
CHANGED
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.
|
4
|
+
version: 1.0.141
|
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-
|
11
|
+
date: 2023-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|