brick 1.0.146 → 1.0.148

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: 5a3f6fe9aa20dd0fe9ae7058874432a5966dea3b36f79d1e84702728fb010071
4
- data.tar.gz: fc6fa3766a3413f9ba4df5cd1d8361bea351a180f6a7950a3ef1f9427145884b
3
+ metadata.gz: 66301eacecd8c8f5dc5587f234ce373673a9d8544dad12e6ae27e0b1a99bed40
4
+ data.tar.gz: 226f44c9814fe1b47db39be49a3c35f499dd8795197523f74e8072de641d4cdd
5
5
  SHA512:
6
- metadata.gz: 64f5575cfba4fa0a7983ae4621941a3da6622ed70f606c7c418814d1041a10fec4b522cc0f4741faa6677681a1453b92f0cce31ad36edba9cb0f0c4ca9e812e2
7
- data.tar.gz: e5aa7fa963d0756a9fa8946daef90f03e1d6e38210811a58c7f901895d44132785222095ea1b3f56223ef663328ecc3536d35a9b8bed6e97fde94edb5f4d5250
6
+ metadata.gz: ab20a8565d71699db3bb960dc82e8091072be169011f62beb505527e5946f406fde89dab610d26717d3be118fab0ee7daf38c774c6f0a92f9d655f54cba3d0d5
7
+ data.tar.gz: 2b2f29c67712b001bfe43a03b881eec48eee7cf73686fe54da8e4aa30e88af91f7b23f67e95620eccde2b171a44f4e117d0326451c5917c4ef699b6141344382
data/lib/brick/config.rb CHANGED
@@ -299,6 +299,14 @@ module Brick
299
299
  @mutex.synchronize { @models_inherit_from = value }
300
300
  end
301
301
 
302
+ def controllers_inherit_from
303
+ @mutex.synchronize { @controllers_inherit_from }
304
+ end
305
+
306
+ def controllers_inherit_from=(value)
307
+ @mutex.synchronize { @controllers_inherit_from = value }
308
+ end
309
+
302
310
  def table_name_prefixes
303
311
  @mutex.synchronize { @table_name_prefixes }
304
312
  end
@@ -85,6 +85,10 @@ module ActiveRecord
85
85
  (respond_to?(:attribute_types) && (attr_types = attribute_types[col.name]).respond_to?(:coder) &&
86
86
  (attr_types.coder.is_a?(Class) ? attr_types.coder : attr_types.coder&.class)&.name&.end_with?('JSON'))
87
87
  end
88
+
89
+ def brick_foreign_type(assoc)
90
+ reflect_on_association(assoc).foreign_type || "#{assoc}_type"
91
+ end
88
92
  end
89
93
 
90
94
  def self._brick_primary_key(relation = nil)
@@ -895,15 +899,15 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
895
899
  # Add the ordered series of columns derived from the BT based on its DSL
896
900
  if (bt_cols = klass._br_bt_descrip[v])
897
901
  bt_cols.values.each do |v1|
898
- v1.each { |v2| s << "\"#{v2.last}\"" if v2.length > 1 }
902
+ v1.each { |v2| s << _br_quoted_name(v2.last) if v2.length > 1 }
899
903
  end
900
904
  elsif (cc_cols = klass._br_cust_cols[v])
901
- cc_cols.first.each { |v1| s << "\"#{v1.last}\"" if v1.length > 1 }
905
+ cc_cols.first.each { |v1| s << _br_quoted_name(v1.last) if v1.length > 1 }
902
906
  else
903
907
  s << v
904
908
  end
905
909
  else # String stuff (which defines a custom ORDER BY) just comes straight through
906
- v = v.split('.').map { |x| "\"#{x}\"" }.join('.')
910
+ v = v.split('.').map { |x| _br_quoted_name(x) }.join('.')
907
911
  s << v
908
912
  # Avoid "PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list" in Postgres
909
913
  selects << v if is_distinct
@@ -959,7 +963,7 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
959
963
  begin
960
964
  send(method, *args, **kwargs, &block) # method will be something like :uniq or :each
961
965
  rescue ActiveModel::MissingAttributeError => e
962
- if (err_msg = e.message).start_with?('missing attribute: ') &&
966
+ if e.message.start_with?('missing attribute: ') &&
963
967
  klass.column_names.include?(col_name = e.message[19..-1])
964
968
  (dup_rel = dup).select_values << col_name
965
969
  ret = dup_rel.brick_(method, *args, brick_orig_relation: (brick_orig_relation ||= self), **kwargs, &block)
@@ -997,8 +1001,10 @@ Might want to add this in your brick.rb:
997
1001
  end
998
1002
 
999
1003
  def _br_quoted_name(name)
1000
- if is_mysql
1001
- "`#{name}`"
1004
+ if name == '*'
1005
+ name
1006
+ elsif is_mysql
1007
+ "`#{name.gsub('.', '`.`')}`"
1002
1008
  elsif is_postgres || is_mssql
1003
1009
  "\"#{(name).gsub('.', '"."')}\""
1004
1010
  else
@@ -1258,7 +1264,7 @@ end
1258
1264
  # %%% Perhaps an option to use the first module just as schema, and additional modules as namespace with a table name prefix applied
1259
1265
 
1260
1266
  # AVO Resource
1261
- elsif base_module == Object && Object.const_defined?('Avo') && requested.end_with?('Resource') &&
1267
+ elsif base_module == Object && Object.const_defined?('Avo') && ::Avo.respond_to?(:railtie_namespace) && requested.end_with?('Resource') &&
1262
1268
  # Expect that anything called MotorResource or SpinaResource could be from those administrative gems
1263
1269
  requested.length > 8 && ['MotorResource', 'SpinaResource'].exclude?(requested)
1264
1270
  if (model = Object.const_get(requested[0..-9])) && model < ActiveRecord::Base
@@ -1310,7 +1316,7 @@ end
1310
1316
  built_class, code = result
1311
1317
  puts "\n#{code}\n"
1312
1318
  built_class
1313
- elsif ::Brick.config.sti_namespace_prefixes&.key?("::#{class_name}") && !schema_name
1319
+ elsif !schema_name && ::Brick.config.sti_namespace_prefixes&.key?("::#{class_name}")
1314
1320
  # module_prefixes = type_name.split('::')
1315
1321
  # path = base_module.name.split('::')[0..-2] + []
1316
1322
  # module_prefixes.unshift('') unless module_prefixes.first.blank?
@@ -1384,7 +1390,12 @@ class Object
1384
1390
  relation = relations["#{schema_name}.#{matching}"]
1385
1391
  end
1386
1392
  full_name = if relation || schema_name.blank?
1387
- inheritable_name || model_name
1393
+ if singular_table_name != table_name.singularize && # %%% Try this with http://localhost:3000/brick/spree/property_translations
1394
+ (schema_module = ::Brick.config.table_name_prefixes.find { |k, v| table_name.start_with?(k) }&.last&.constantize)
1395
+ "#{schema_module&.name}::#{inheritable_name || model_name}"
1396
+ else
1397
+ inheritable_name || model_name
1398
+ end
1388
1399
  else # Prefix the schema to the table name + prefix the schema namespace to the class name
1389
1400
  schema_module = if schema_name.is_a?(Module) # from an auto-STI namespace?
1390
1401
  schema_name
@@ -1423,7 +1434,7 @@ class Object
1423
1434
  hmts = nil
1424
1435
  code = +"class #{full_name} < #{base_model.name}\n"
1425
1436
  built_model = Class.new(base_model) do |new_model_class|
1426
- (schema_module || Object).const_set((inheritable_name || model_name).to_sym, new_model_class)
1437
+ (schema_module || Object).const_set((chosen_name = (inheritable_name || model_name)).to_sym, new_model_class)
1427
1438
  if inheritable_name
1428
1439
  new_model_class.define_singleton_method :inherited do |subclass|
1429
1440
  super(subclass)
@@ -1493,7 +1504,7 @@ class Object
1493
1504
  unless is_sti
1494
1505
  fks = relation[:fks] || {}
1495
1506
  # Do the bulk of the has_many / belongs_to processing, and store details about HMT so they can be done at the very last
1496
- hmts = fks.each_with_object(Hash.new { |h, k| h[k] = [] }) do |fk, hmts|
1507
+ fks.each_with_object(Hash.new { |h, k| h[k] = [] }) do |fk, hmts|
1497
1508
  # The key in each hash entry (fk.first) is the constraint name
1498
1509
  inverse_assoc_name = (assoc = fk.last)[:inverse]&.fetch(:assoc_name, nil)
1499
1510
  if (invs = assoc[:inverse_table]).is_a?(Array)
@@ -1516,6 +1527,13 @@ class Object
1516
1527
  # end
1517
1528
  # end
1518
1529
  end
1530
+
1531
+ # Enable Turbo Stream if possible -- equivalent of: broadcasts_to ->(comment) { :comments }
1532
+ if Object.const_defined?(:ApplicationCable) && Object.const_defined?(:Turbo) && Turbo.const_defined?(:Broadcastable) && respond_to?(:broadcasts_to)
1533
+ relation[:broadcasts] = true
1534
+ self.broadcasts_to ->(model) { (model&.class&.name || chosen_name).underscore.pluralize.to_sym }
1535
+ code << " broadcasts_to ->(#{chosen_name}) { #{chosen_name}&.class&.name&.underscore&.pluralize&.to_sym }\n"
1536
+ end
1519
1537
  end # class definition
1520
1538
  # Having this separate -- will this now work out better?
1521
1539
  built_model.class_exec do
@@ -1588,7 +1606,8 @@ class Object
1588
1606
  if assoc.key?(:polymorphic) ||
1589
1607
  # If a polymorphic association is missing but could be established then go ahead and put it into place.
1590
1608
  relations[assoc[:inverse_table]][:class_name].constantize.reflect_on_all_associations.find { |inv_assoc| !inv_assoc.belongs_to? && inv_assoc.options[:as].to_s == assoc[:assoc_name] }
1591
- assoc[:polymorphic] ||= (options[:polymorphic] = true)
1609
+ assoc[:polymorphic] ||= true
1610
+ options[:polymorphic] = true
1592
1611
  else
1593
1612
  need_class_name = singular_table_name.underscore != assoc_name
1594
1613
  need_fk = "#{assoc_name}_id" != assoc[:fk]
@@ -1686,15 +1705,33 @@ class Object
1686
1705
  # (More information on https://docs.avohq.io/2.0/controllers.html)
1687
1706
  controller_base = Avo::ResourcesController
1688
1707
  end
1708
+ if !model&.table_exists? && (tn = model&.table_name)
1709
+ msg = +"Can't find table \"#{tn}\" for model #{model.name}."
1710
+ puts
1711
+ # Potential bad inflection?
1712
+ if (dym = DidYouMean::SpellChecker.new(dictionary: ::Brick.relations.keys).correct(tn)).present?
1713
+ msg << "\nIf you meant \"#{found_dym = dym.first}\" then to avoid this message add this entry into inflections.rb:\n"
1714
+ msg << " inflect.irregular '#{model.name}', '#{found_dym.camelize}'"
1715
+ model.table_name = found_dym
1716
+ puts "WARNING: #{msg}"
1717
+ else
1718
+ puts "ERROR: #{msg}"
1719
+ end
1720
+ puts
1721
+ end
1689
1722
  table_name = model&.table_name || ActiveSupport::Inflector.underscore(plural_class_name)
1690
1723
  singular_table_name = ActiveSupport::Inflector.singularize(ActiveSupport::Inflector.underscore(plural_class_name))
1691
1724
  pk = model&._brick_primary_key(relations.fetch(table_name, nil))
1692
1725
  is_postgres = ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
1693
1726
  is_mysql = ['Mysql2', 'Trilogy'].include?(ActiveRecord::Base.connection.adapter_name)
1694
1727
 
1695
- code = +"class #{namespace}::#{class_name} < #{controller_base&.name || 'ApplicationController'}\n"
1696
- built_controller = Class.new(controller_base || ActionController::Base) do |new_controller_class|
1697
- (namespace || Object).const_set(class_name.to_sym, new_controller_class)
1728
+ namespace = nil if namespace == ::Object
1729
+ controller_base ||= ::Brick.config.controllers_inherit_from if ::Brick.config.controllers_inherit_from
1730
+ controller_base = controller_base.constantize if controller_base.is_a?(String)
1731
+ controller_base ||= ActionController::Base
1732
+ code = +"class #{namespace&.name}::#{class_name} < #{controller_base&.name}\n"
1733
+ built_controller = Class.new(controller_base) do |new_controller_class|
1734
+ (namespace || ::Object).const_set(class_name.to_sym, new_controller_class)
1698
1735
 
1699
1736
  # Add a hash for the inline style to the content-security-policy if one is present
1700
1737
  self.define_method(:add_csp_hash) do |style_value = nil|
@@ -2014,7 +2051,15 @@ class Object
2014
2051
  end
2015
2052
  end
2016
2053
 
2017
- unless is_openapi || is_avo
2054
+ unless is_openapi || is_avo # Normal controller (non-API)
2055
+ if controller_base == ActionController::Base && ::Brick.relations[model.table_name].fetch(:broadcasts, nil)
2056
+ puts "WARNING: If you intend to use the #{model.name} model with Turbo Stream broadcasts,
2057
+ you will want to have its controller inherit from ApplicationController instead of
2058
+ ActionController::Base (which as you can see below is what it currently does). To enact
2059
+ this for every auto-generated controller, you can uncomment this line in brick.rb:
2060
+ ::Brick.controllers_inherit_from = 'ApplicationController'"
2061
+ end
2062
+
2018
2063
  # Skip showing Bullet gem optimisation messages
2019
2064
  if Object.const_defined?('Bullet') && Bullet.respond_to?(:enable?)
2020
2065
  around_action :skip_bullet
@@ -2316,6 +2361,7 @@ end.class_exec do
2316
2361
 
2317
2362
  orig_schema = nil
2318
2363
  if (relations = ::Brick.relations).empty?
2364
+ ::Brick.remove_instance_variable(:@_additional_references_loaded) if ::Brick.instance_variable_defined?(:@_additional_references_loaded)
2319
2365
  # Very first thing, load inflections since we'll be using .pluralize and .singularize on table and model names
2320
2366
  if File.exist?(inflections = ::Rails.root.join('config/initializers/inflections.rb'))
2321
2367
  load inflections
@@ -996,7 +996,7 @@ callbacks = {} %>
996
996
  css << "<% bts = { #{
997
997
  bt_items = bts.each_with_object([]) do |v, s|
998
998
  foreign_models = if v.last[2] # Polymorphic?
999
- poly_cols << @_brick_model.reflect_on_association(v[1].first).foreign_type
999
+ poly_cols << @_brick_model.brick_foreign_type(v[1].first)
1000
1000
  v.last[1].each_with_object([]) { |x, s| s << "[#{x.name}, #{x.primary_key.inspect}]" }.join(', ')
1001
1001
  else
1002
1002
  "[#{v.last[1].name}, #{v.last[1].primary_key.inspect}]"
@@ -1443,11 +1443,11 @@ end
1443
1443
  entry.to_s.start_with?('@_') ||
1444
1444
  ['@cache_hit', '@marked_for_same_origin_verification', '@view_renderer', '@view_flow', '@output_buffer', '@virtual_path'].include?(entry.to_s)
1445
1445
  end).present?
1446
- msg = \"Can't find resource \\\"#{table_name}\\\".\"
1447
- # Can't be sure otherwise of what is up, so check DidYouMean and offer a suggestion.
1446
+ msg = +\"Can't find resource \\\"#{table_name}\\\".\"
1447
+ # Can't be sure otherwise of what is up, so check DidYouMean and offer a suggestion.
1448
1448
  if (dym = DidYouMean::SpellChecker.new(dictionary: dym_list).correct('@#{table_name}')).present?
1449
1449
  msg << \"\nIf you meant \\\"#\{found_dym = dym.first[1..-1]}\\\" then to avoid this message add this entry into inflections.rb:\n\"
1450
- msg << \" inflect.singular('#\{found_dym}', '#{obj_name}')\"
1450
+ msg << \" inflect.irregular '#{obj_name}', '#\{found_dym}'\"
1451
1451
  puts
1452
1452
  puts \"WARNING: #\{msg}\"
1453
1453
  puts
@@ -1630,6 +1630,12 @@ end
1630
1630
  <%= form_for(obj.becomes(#{model_name}), options) do |f| %>
1631
1631
  <table class=\"shadow\">
1632
1632
  <% has_fields = false
1633
+ # If it's a new record, set any default polymorphic types
1634
+ bts.each do |_k, v|
1635
+ if v[2]
1636
+ @#{obj_name}.send(\"#\{model.brick_foreign_type(v.first)}=\", v[1].first&.first&.name)
1637
+ end
1638
+ end if @#{obj_name}.new_record?
1633
1639
  @#{obj_name}.attributes.each do |k, val|
1634
1640
  next if !(col = #{model_name}.columns_hash[k]) ||
1635
1641
  (#{(pk.map(&:to_s) || []).inspect}.include?(k) && !bts.key?(k)) ||
@@ -1642,7 +1648,7 @@ end
1642
1648
  bt_name = bt[1].map { |x| x.first.name }.join('/')
1643
1649
  # %%% Only do this if the user has permissions to edit this bt field
1644
1650
  if bt[2] # Polymorphic?
1645
- poly_class_name = orig_poly_name = @#{obj_name}.send(\"#\{bt.first\}_type\")
1651
+ poly_class_name = orig_poly_name = @#{obj_name}.send(model.brick_foreign_type(bt.first))
1646
1652
  bt_pair = nil
1647
1653
  loop do
1648
1654
  bt_pair = bt[1].find { |pair| pair.first.name == poly_class_name }
@@ -1657,9 +1663,8 @@ end
1657
1663
  # descrips = @_brick_bt_descrip[bt.first][bt_class]
1658
1664
  poly_id = @#{obj_name}.send(\"#\{bt.first\}_id\")
1659
1665
  # bt_class.order(obj_pk = bt_class.primary_key).each { |obj| option_detail << [obj.brick_descrip(nil, obj_pk), obj.send(obj_pk)] }
1660
- else # No polymorphism, so just get the first one
1661
- bt_pair = bt[1].first
1662
1666
  end
1667
+ bt_pair ||= bt[1].first # If there's no polymorphism (or polymorphism status is unknown), just get the first one
1663
1668
  bt_class = bt_pair&.first
1664
1669
  if bt.length < 4
1665
1670
  bt << (option_detail = [[\"(No #\{bt_name\} chosen)\", '^^^brick_NULL^^^']])
@@ -1706,7 +1711,7 @@ end
1706
1711
 
1707
1712
  if (pk = hm.first.klass.primary_key)
1708
1713
  hm_singular_name = (hm_name = hm.first.name.to_s).singularize.underscore
1709
- obj_pk = (pk.is_a?(Array) ? pk : [pk]).each_with_object([]) { |pk_part, s| s << "#{hm_singular_name}.#{pk_part}" }.join(', ')
1714
+ obj_br_pk = (pk.is_a?(Array) ? pk : [pk]).each_with_object([]) { |pk_part, s| s << "br_#{hm_singular_name}.#{pk_part}" }.join(', ')
1710
1715
  poly_fix = if (poly_type = (hm.first.options[:as] && hm.first.type))
1711
1716
  "
1712
1717
  # Let's fix an unexpected \"feature\" of AR -- when going through a polymorphic has_many
@@ -1736,21 +1741,23 @@ end
1736
1741
  else
1737
1742
  collection = @#{obj_name}.#{hm_name}
1738
1743
  end
1744
+ err_msg = nil
1739
1745
  case collection
1740
1746
  when ActiveRecord::Relation # has_many (which comes in as a CollectionProxy) or a has_one#{
1741
1747
  poly_fix}
1742
1748
  collection2, descrip_cols = begin
1743
1749
  collection.brick_list
1744
- rescue
1750
+ rescue => e
1751
+ err_msg = '(error)'
1752
+ puts \"ERROR when referencing #\{collection.klass.name}: #\{e.message}\"
1745
1753
  end
1746
1754
  when ActiveRecord::Base # Object from a has_one :through
1747
1755
  collection2 = [collection]
1748
1756
  else # We get an array back when AR < 4.2
1749
1757
  collection2 = collection.to_a.compact
1750
1758
  end
1751
- collection2 = collection2.brick_(:uniq)
1752
- if collection2.empty? %>
1753
- <tr><td>(none)</td></tr>
1759
+ if (collection2 = collection2&.brick_(:uniq)).blank? %>
1760
+ <tr><td<%= ' class=\"orphan\"'.html_safe if err_msg %>><%= err_msg || '(none)' %></td></tr>
1754
1761
  <% else
1755
1762
  collection2.each do |br_#{hm_singular_name}| %>
1756
1763
  <tr><td><%= br_descrip = if br_#{hm_singular_name}.respond_to?(descrip_cols&.first&.first&.last)
@@ -1763,7 +1770,7 @@ end
1763
1770
  pks.map! { |pk| br_#{hm_singular_name}.send(pk).to_s }
1764
1771
  \"#\{klass.name} ##\{pks.join(', ')}\"
1765
1772
  end
1766
- link_to(br_descrip, #{hm.first.klass._brick_index(:singular)}_path(slashify(br_#{obj_pk}))) %></td></tr>
1773
+ link_to(br_descrip, #{hm.first.klass._brick_index(:singular)}_path(slashify(#{obj_br_pk}))) %></td></tr>
1767
1774
  <% end %>
1768
1775
  <% end %>
1769
1776
  </table>"
@@ -86,8 +86,7 @@ module Brick::Rails::FormTags
86
86
  if (bt || composite_bt_names[col_name])
87
87
  if bt[2] # Polymorphic?
88
88
  if (poly_id = obj.send("#{bt.first}_id"))
89
- # Was: obj.send("#{bt.first}_type")
90
- bt_class = obj.send(obj.class.reflect_on_association(bt.first).foreign_type)
89
+ bt_class = obj.send(klass.brick_foreign_type(bt.first))
91
90
  base_class_underscored = (::Brick.existing_stis[bt_class] || bt_class).constantize.base_class._brick_index(:singular)
92
91
  out << link_to("#{bt_class} ##{poly_id}", send("#{base_class_underscored}_path".to_sym, poly_id))
93
92
  end
@@ -98,7 +97,7 @@ module Brick::Rails::FormTags
98
97
  bt_id_col = if descrips.nil?
99
98
  puts "Caught it in the act for obj / #{col_name}!"
100
99
  elsif descrips.length == 1
101
- [obj.class.reflect_on_association(bt.first)&.foreign_key]
100
+ [klass.reflect_on_association(bt.first)&.foreign_key]
102
101
  else
103
102
  descrips.last
104
103
  end
@@ -132,7 +131,7 @@ module Brick::Rails::FormTags
132
131
  end
133
132
  elsif obj.respond_to?(ct_col = hms_col[1].to_sym) && (ct = obj.send(ct_col)&.to_i)&.positive?
134
133
  predicates = hms_col[2].each_with_object({}) { |v, s| s[v.first] = v.last.is_a?(String) ? v.last : obj.send(v.last) }
135
- predicates.each { |k, v| predicates[k] = obj.class.name if v == '[sti_type]' }
134
+ predicates.each { |k, v| predicates[k] = klass.name if v == '[sti_type]' }
136
135
  out << "#{link_to("#{ct || 'View'} #{hms_col.first}",
137
136
  send("#{hm_klass._brick_index}_path".to_sym, predicates))}\n"
138
137
  end
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 146
8
+ TINY = 148
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
@@ -188,6 +188,10 @@ module Brick
188
188
  bts, hms = model.reflect_on_all_associations.each_with_object([{}, {}]) do |a, s|
189
189
  # %%% The time will come when we will support type checking of composite foreign keys!
190
190
  # binding.pry if a.foreign_key.is_a?(Array)
191
+ if a.belongs_to? && !a.polymorphic? && ::Brick.config.polymorphics.fetch(full_assoc_name = "#{model.table_name}.#{a.name}", nil)
192
+ puts "Based on inclusion in ::Brick.polymorphics, marking association #{full_assoc_name} as being polymorphic."
193
+ a.options[:polymorphic] = true
194
+ end
191
195
  next unless a.polymorphic? || (!a.belongs_to? && (through = a.options[:through])) ||
192
196
  (a.klass && ::Brick.config.exclude_tables.exclude?(a.klass.table_name) &&
193
197
  (!a.belongs_to? || model_cols[a.foreign_key]&.type == pk_type)
@@ -395,6 +399,11 @@ module Brick
395
399
  Brick.config.models_inherit_from = value
396
400
  end
397
401
 
402
+ # @api public
403
+ def controllers_inherit_from=(value)
404
+ Brick.config.controllers_inherit_from = value
405
+ end
406
+
398
407
  # @api public
399
408
  def table_name_prefixes=(value)
400
409
  Brick.config.table_name_prefixes = value
@@ -549,7 +558,7 @@ module Brick
549
558
  ::Brick._add_bt_and_hm([nil, table_name, poly, nil, primary_table, "(brick) #{table_name}_#{poly}"], relations,
550
559
  type, # Polymorphic class
551
560
  is_optional)
552
- else
561
+ elsif relations.present?
553
562
  missing_stis[primary_table] = type unless ::Brick.existing_stis.key?(type)
554
563
  end
555
564
  end
@@ -1388,13 +1397,13 @@ ActiveSupport.on_load(:active_record) do
1388
1397
  end
1389
1398
  end
1390
1399
 
1391
- if ActiveRecord.version < ::Gem::Version.new('6.1') &&
1400
+ if ActiveRecord.version < ::Gem::Version.new('6.1.4') &&
1392
1401
  Psych.method(:load).parameters.any? { |param| param.first == :key && param.last == :aliases }
1393
1402
  Psych.class_exec do
1394
1403
  class << self
1395
1404
  alias _original_load load
1396
1405
  def load(yaml, *args, **kwargs)
1397
- if caller.first.end_with?("`database_configuration'") && kwargs[:aliases].nil?
1406
+ if kwargs[:aliases].nil? && caller[0..4].any? { |line| line.end_with?("`database_configuration'") }
1398
1407
  kwargs[:aliases] = true
1399
1408
  end
1400
1409
  _original_load(yaml, *args, **kwargs)
@@ -1600,7 +1609,7 @@ if Gem::Specification.all_names.find { |g| g.start_with?('awesome_nested_set-')
1600
1609
  ::CollectiveIdea::Acts::NestedSet::Columns.class_exec do
1601
1610
  alias _brick_order_column_name order_column_name
1602
1611
  def order_column_name
1603
- unless (ord_col = _brick_order_column_name).start_with?(tbl_prefix = "#{table_name}.")
1612
+ unless (ord_col = _brick_order_column_name).start_with?(tbl_prefix = +"#{table_name}.")
1604
1613
  ord_col = tbl_prefix << ord_col
1605
1614
  end
1606
1615
  ord_col
@@ -176,6 +176,12 @@ if ActiveRecord::Base.respond_to?(:brick_select) && !::Brick.initializer_loaded
176
176
  # # Class that auto-generated models should inherit from
177
177
  # Brick.models_inherit_from = ApplicationRecord
178
178
 
179
+ # # Class that auto-generated controllers should inherit from
180
+ # # (Would generally want to un-comment this line if you want to enforce any authentication which is
181
+ # # established in your ApplicationController, or for auto-created controllers to support
182
+ # # Turbo Stream broadcasts.)
183
+ # ::Brick.controllers_inherit_from = 'ApplicationController'
184
+
179
185
  # # When table names have specific prefixes automatically place them in their own module with a table_name_prefix.
180
186
  # Brick.table_name_prefixes = { 'nav_' => 'Navigation' }
181
187
 
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.146
4
+ version: 1.0.148
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-25 00:00:00.000000000 Z
11
+ date: 2023-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord