brick 1.0.136 → 1.0.137

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: f34d7342f9445995a1cb28a3b42eeecaf4f90483eb2fc5e848517536c3631287
4
- data.tar.gz: 68d308c36abffbc024c5439c06863777d4512a85137ef34566a7bfe0d9e590a1
3
+ metadata.gz: f25abe6f88b55efadd50c9deb65e7d9aabac31482a77f0f911f84157d4394079
4
+ data.tar.gz: a437b8efd9116a7c1e5a81fa6d67a66755b15a275db56717ecb7abe76bbbb50a
5
5
  SHA512:
6
- metadata.gz: f45d7f79a0d484f6c3b1276545f7fbabd854b16b8fae54bd428f7fd8893e572675ddb7c8b5e3a08d8df30437be7ee5ac3e34af71f652ed341d2b08ebe630add7
7
- data.tar.gz: 213f3f2c4b3984adf58c66cef21282c3cc43bd4283c5afba356102603b68be37235f52f41108b6820f41aee63e04eaf42348c8eef0f7ba4e17d3405666f22ebb
6
+ metadata.gz: 21ea85675d6e711261c8873c12187d78ecfdb53961a8ba795d35210b2a7cd00940d3522def3f3c8f10d37e3f7a8409f68efefc923798847b602f8d8afe24316f
7
+ data.tar.gz: b34c4d0396aea262f73e34bc25d4f0e2d9e2d3bddb36aa1293d7e7293edfed9f930318724c8471f11344822b6faa4afa942018148ed59cfa27d50eef6bca0eea
@@ -989,7 +989,7 @@ end
989
989
  if Object.const_defined?('ActionView')
990
990
  require 'brick/frameworks/rails/form_tags'
991
991
  require 'brick/frameworks/rails/form_builder'
992
- module ActionView::Helpers
992
+ module ::ActionView::Helpers
993
993
  module FormTagHelper
994
994
  include ::Brick::Rails::FormTags
995
995
  end
@@ -999,8 +999,8 @@ if Object.const_defined?('ActionView')
999
999
  end
1000
1000
 
1001
1001
  # FormBuilder#field_id isn't available in Rails < 7.0. This is a rudimentary version with no `index`.
1002
- unless ActionView::Helpers::FormBuilder.methods.include?(:field_id)
1003
- ActionView::Helpers::FormBuilder.class_exec do
1002
+ unless ::ActionView::Helpers::FormBuilder.methods.include?(:field_id)
1003
+ ::ActionView::Helpers::FormBuilder.class_exec do
1004
1004
  def field_id(method)
1005
1005
  [object_name, method.to_s].join('_')
1006
1006
  end
@@ -1149,7 +1149,7 @@ Module.class_exec do
1149
1149
  ::Brick.is_oracle ? class_name.upcase : class_name,
1150
1150
  (plural_class_name = class_name.pluralize)].find { |s| Brick.db_schemas&.include?(s) }&.camelize ||
1151
1151
  (::Brick.config.sti_namespace_prefixes&.key?("::#{class_name}::") && class_name) ||
1152
- (::Brick.config.table_name_prefixes.values.include?(class_name) && class_name))
1152
+ (::Brick.config.table_name_prefixes&.values&.include?(class_name) && class_name))
1153
1153
  return self.const_get(schema_name) if !is_tnp_module && self.const_defined?(schema_name)
1154
1154
 
1155
1155
  # Build out a module for the schema if it's namespaced
@@ -1942,8 +1942,9 @@ class Object
1942
1942
  end
1943
1943
  render json: { result: ::Brick.unexclude_column(table_name, col) }
1944
1944
  else
1945
- instance_variable_set("@#{singular_table_name}".to_sym,
1946
- model.send(:create, send(params_name_sym)))
1945
+ @_lookup_context.instance_variable_set("@#{singular_table_name}".to_sym,
1946
+ model.send(:create, send(params_name_sym)))
1947
+ @_lookup_context.instance_variable_set(:@_brick_model, model)
1947
1948
  index
1948
1949
  render :index
1949
1950
  end
@@ -1430,6 +1430,12 @@ end
1430
1430
  end
1431
1431
  end
1432
1432
 
1433
+ # %%% Why in the Canvas LMS app does ActionView::Helpers get cleared / reloaded, or otherwise lose access to #brick_grid ???
1434
+ # Possible fix if somewhere we can implement the #include with:
1435
+ # (ActiveSupport.const_defined?('Reloader') ? ActiveSupport : ActionDispatch)::Reloader.to_prepare do ... end
1436
+ # or
1437
+ # Rails.application.reloader.to_prepare do ... end
1438
+ self.class.class_exec { include ::Brick::Rails::FormTags } unless respond_to?(:brick_grid)
1433
1439
  # Write out the mega-grid
1434
1440
  brick_grid(@#{table_name}, @_brick_bt_descrip, @_brick_sequence, @_brick_incl, @_brick_excl,
1435
1441
  cols, poly_cols, bts, #{hms_keys.inspect}, {#{hms_columns.join(', ')}}) %>
@@ -36,9 +36,9 @@ module Brick::Rails::FormTags
36
36
  end
37
37
  sequence.reject! { |nm| exclusions.include?(nm) } if exclusions
38
38
  out << sequence.each_with_object(+'') do |col_name, s|
39
+ s << '<th '
39
40
  if (col = cols[col_name]).is_a?(ActiveRecord::ConnectionAdapters::Column)
40
- s << '<th '
41
- s << "title=\"#{col.comment}\"" if col.respond_to?(:comment) && !col.comment.blank?
41
+ s << "title=\"#{col.comment}\" " if col.respond_to?(:comment) && !col.comment.blank?
42
42
  s << if (bt = bts[col_name])
43
43
  # Allow sorting for any BT except polymorphics
44
44
  "x-order=\"#{bt.first.to_s + '"' unless bt[2]}>BT " +
@@ -49,18 +49,18 @@ module Brick::Rails::FormTags
49
49
  elsif col # HM column
50
50
  options = {}
51
51
  options[col[1].inheritance_column] = col[1].name unless col[1] == col[1].base_class
52
- s << "<th x-order=\"#{col_name + '"' if true}>#{col[2]} "
52
+ s << "x-order=\"#{col_name + '"' if true}>#{col[2]} "
53
53
  s << (col.first ? "#{col[3]}" : "#{link_to(col[3], send("#{col[1]._brick_index}_path", options))}")
54
54
  elsif cust_cols.key?(col_name) # Custom column
55
- s << "<th x-order=\"#{col_name}\">#{col_name}"
55
+ s << "x-order=\"#{col_name}\">#{col_name}"
56
56
  elsif col_name.is_a?(Symbol) && (hot = bts[col_name]) # has_one :through
57
- s << "<th x-order=\"#{hot.first.to_s}\">HOT " +
57
+ s << "x-order=\"#{hot.first.to_s}\">HOT " +
58
58
  hot[1].map { |hot_pair| hot_pair.first.bt_link(col_name) }.join(' ')
59
59
  elsif (bt = composite_bt_names[col_name])
60
- s << "<th x-order=\"#{bt.first.to_s + '"' unless bt[2]}>BT comp " +
60
+ s << "x-order=\"#{bt.first.to_s + '"' unless bt[2]}>BT comp " +
61
61
  bt[1].map { |bt_pair| bt_pair.first.bt_link(bt.first) }.join(' ')
62
62
  else # Bad column name!
63
- s << "<th title=\"<< Unknown column >>\">#{col_name}"
63
+ s << "title=\"<< Unknown column >>\">#{col_name}"
64
64
  end
65
65
  s << '</th>'
66
66
  end
@@ -93,18 +93,20 @@ module Brick::Rails::FormTags
93
93
  end
94
94
  else # BT or HOT
95
95
  bt_class = bt[1].first.first
96
- descrips = bt_descrip[bt.first][bt_class]
97
- bt_id_col = if descrips.nil?
98
- puts "Caught it in the act for obj / #{col_name}!"
99
- elsif descrips.length == 1
100
- [obj.class.reflect_on_association(bt.first)&.foreign_key]
101
- else
102
- descrips.last
103
- end
104
- bt_txt = bt_class.brick_descrip(
105
- # 0..62 because Postgres column names are limited to 63 characters
106
- obj, descrips[0..-2].map { |id| obj.send(id.last[0..62]) }, bt_id_col
107
- )
96
+ if bt_descrip
97
+ descrips = bt_descrip[bt.first][bt_class]
98
+ bt_id_col = if descrips.nil?
99
+ puts "Caught it in the act for obj / #{col_name}!"
100
+ elsif descrips.length == 1
101
+ [obj.class.reflect_on_association(bt.first)&.foreign_key]
102
+ else
103
+ descrips.last
104
+ end
105
+ end
106
+ br_descrip_args = [obj]
107
+ # 0..62 because Postgres column names are limited to 63 characters
108
+ br_descrip_args += [descrips[0..-2].map { |id| obj.send(id.last[0..62]) }, bt_id_col] if descrips
109
+ bt_txt = bt_class.brick_descrip(*br_descrip_args)
108
110
  bt_txt = ::Brick::Rails.display_binary(bt_txt).html_safe if bt_txt&.encoding&.name == 'ASCII-8BIT'
109
111
  bt_txt ||= "<span class=\"orphan\">&lt;&lt; Orphaned ID: #{val} >></span>" if val
110
112
  bt_id = bt_id_col&.map { |id_col| obj.respond_to?(id_sym = id_col.to_sym) ? obj.send(id_sym) : id_col }
@@ -128,13 +130,11 @@ module Brick::Rails::FormTags
128
130
  end
129
131
  out << link_to(ho_txt, send("#{hm_klass.base_class._brick_index(:singular)}_path".to_sym, ho_id))
130
132
  end
131
- else
132
- if (ct = obj.send(hms_col[1].to_sym)&.to_i)&.positive?
133
- predicates = hms_col[2].each_with_object({}) { |v, s| s[v.first] = v.last.is_a?(String) ? v.last : obj.send(v.last) }
134
- predicates.each { |k, v| predicates[k] = obj.class.name if v == '[sti_type]' }
135
- out << "#{link_to("#{ct || 'View'} #{hms_col.first}",
136
- send("#{hm_klass._brick_index}_path".to_sym, predicates))}\n"
137
- end
133
+ elsif obj.respond_to?(ct_col = hms_col[1].to_sym) && (ct = obj.send(ct_col)&.to_i)&.positive?
134
+ 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]' }
136
+ out << "#{link_to("#{ct || 'View'} #{hms_col.first}",
137
+ send("#{hm_klass._brick_index}_path".to_sym, predicates))}\n"
138
138
  end
139
139
  end
140
140
  elsif (col = cols[col_name]).is_a?(ActiveRecord::ConnectionAdapters::Column)
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 136
8
+ TINY = 137
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
@@ -163,6 +163,8 @@ module Brick
163
163
 
164
164
  # All tables and views (what Postgres calls "relations" including column and foreign key info)
165
165
  def relations
166
+ return {} if ::ActiveRecord::Base.connection_handler.connection_pool_list.blank?
167
+
166
168
  # Key our list of relations for this connection off of the connection pool's object_id
167
169
  (@relations ||= {})[ActiveRecord::Base.connection_pool.object_id] ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = {} } }
168
170
  end
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.136
4
+ version: 1.0.137
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-04-28 00:00:00.000000000 Z
11
+ date: 2023-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord