brick 1.0.252 → 1.0.254

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: 7bb30040fa7e3a7e755f0d853559f3fe2c9d2dc94af4b6ffbaceb39ef41d981f
4
- data.tar.gz: 21642081c09d80c40b585ee838a8d4436254f4746cf4798e4cfa6eaf04cdccf7
3
+ metadata.gz: 18c3ed9012a36ba6b8df6d62f34a41b4fd7d8fbebe8580c3b961ea1a6643ef0b
4
+ data.tar.gz: 7355cb7700fea0f61f2e44eec2e7919246d963afca8e4f1904273a72006ad3dc
5
5
  SHA512:
6
- metadata.gz: ff10a4dc80c8e663be90c6c6e2b489763312c81834b2303b91799354b91b0bfd8b3d54343ab8ebc17665e17b5a039a53b336822d4529509d1d9f6ba588b403c1
7
- data.tar.gz: '0912de41a2ee1651470e764234fd7394adcba3b16b618fd20359038010fb37a182746b386816fb5673eef7a0848b472fbdec9cea846dd510614cb6286e7b1403'
6
+ metadata.gz: 16dc56a8516865c4c7f594cdf1d571fc831bc31916e9f6827edd3eff2c00ea51048500c500fc421407bcbdf0c46fec75ee1bd60f1244f449418571501eaf878a
7
+ data.tar.gz: 53b2c141cf2f7819c640db261915d01eb85153486a7b3d848b43f3fd4e735b710f55df3f3eb48792ab54446ca536112067df826d58545508109bbbbe6f2d32cf
@@ -28,6 +28,9 @@ if ActiveRecord.version < ::Gem::Version.new('6.0a') && ::Gem::Version.new(RUBY_
28
28
  end
29
29
  end
30
30
 
31
+ # Allow ActiveSupport >= 6.0 to work along with newer versions of the concurrent-ruby gem
32
+ require 'logger' if Gem.loaded_specs['concurrent-ruby']&.version >= ::Gem::Version.new('1.3.5') && Gem.loaded_specs['logger']
33
+
31
34
  # Allow ActiveRecord < 3.2 to work with Ruby 2.7 and later
32
35
  if ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('2.7')
33
36
  if ActiveRecord.version < ::Gem::Version.new('3.2')
@@ -119,7 +122,7 @@ if Object.const_defined?('ActionPack') && !ActionPack.respond_to?(:version)
119
122
  end
120
123
  end
121
124
  end
122
- if Object.const_defined?('Bundler') && Bundler.locked_gems&.dependencies&.key?('action_view')
125
+ if Gem.loaded_specs['actionview']
123
126
  require 'action_view' # Needed for Rails <= 4.0
124
127
  module ::ActionView
125
128
  if Object.const_defined?('ActionView') && !ActionView.respond_to?(:version)
@@ -183,3 +186,27 @@ if ActiveRecord.version < ::Gem::Version.new('5.0') && ::Gem::Version.new(RUBY_V
183
186
  end
184
187
  end
185
188
  end
189
+
190
+ # In ActiveSupport older than 8.1, the quirks_mode keyword argument is passed when #to_json is called. This is
191
+ # incompatible with the JSON gem v3.0 and newer.
192
+ if Object.const_defined?('ActiveSupport') && ActiveRecord.version < ::Gem::Version.new('8.1') && Gem.loaded_specs['json'].version >= ::Gem::Version.new('3.0')
193
+ module ActiveSupport::JSON
194
+ class << self
195
+ def decode(json)
196
+ data = ::JSON.parse(json)
197
+
198
+ if ActiveSupport.parse_json_times
199
+ convert_dates_from(data)
200
+ else
201
+ data
202
+ end
203
+ end
204
+ end
205
+ Encoding::JSONGemEncoder.class_exec do
206
+ private
207
+ def stringify(jsonified)
208
+ ::JSON.generate(jsonified, max_nesting: false)
209
+ end
210
+ end
211
+ end
212
+ end
@@ -2817,7 +2817,7 @@ class Object
2817
2817
  # %%% does this work with STI?
2818
2818
  all_params = params[real_singular_table_name]
2819
2819
  hma.each do |hma_field|
2820
- if upd_hash.fetch(hma_field) == [''] && # No new attachments...
2820
+ if upd_hash.fetch(hma_field, nil) == [''] && # No new attachments...
2821
2821
  all_params&.fetch("_brick_attached_#{hma_field}", nil) # ...and there is something existing
2822
2822
  upd_hash.delete(hma_field)
2823
2823
  end
@@ -1041,7 +1041,7 @@ if (window.brickFontFamily) {
1041
1041
  });
1042
1042
  }
1043
1043
  </script>
1044
- <script src=\"https://apis.google.com/js/api.js\"></script>
1044
+ <script async defer src=\"https://apis.google.com/js/api.js\"></script>
1045
1045
  <script async defer src=\"https://accounts.google.com/gsi/client\" id=\"gapiScript\"></script>
1046
1046
  <script<%= @_request.env['_brick_nonce'] %>>
1047
1047
  document.getElementById(\"gapiScript\").addEventListener(\"onload\",
@@ -1103,6 +1103,59 @@ if (window.brickFontFamily) {
1103
1103
  end
1104
1104
  \"<tr><td colspan=\\\"#\{td_count}\\\">Parent: #\{parent_links.join(' ')}</tr>\".html_safe
1105
1105
  end
1106
+ %><%
1107
+ # Consider getting the name from the association -- hm.first.name -- if a more \"friendly\" alias should be used for a screwy table name
1108
+ # If the resource is missing, has the user simply created an inappropriately pluralised name for a table?
1109
+ @#{res_name} ||= if (dym_list = instance_variables.reject do |entry|
1110
+ entry.to_s.start_with?('@_') ||
1111
+ ['@cache_hit', '@marked_for_same_origin_verification', '@view_renderer', '@view_flow', '@output_buffer', '@virtual_path'].include?(entry.to_s)
1112
+ end).present?
1113
+ msg = +\"Can't find resource \\\"#{res_name}\\\".\"
1114
+ # Can't be sure otherwise of what is up, so check DidYouMean and offer a suggestion.
1115
+ if (dym = DidYouMean::SpellChecker.new(dictionary: dym_list).correct('@#{res_name}')).present?
1116
+ msg << \"\nIf you meant \\\"#\{found_dym = dym.first[1..-1]}\\\" then to avoid this message add this entry into inflections.rb:\n\"
1117
+ msg << \" inflect.irregular '#{obj_name}', '#\{found_dym}'\"
1118
+ puts
1119
+ puts \"WARNING: #\{msg}\"
1120
+ puts
1121
+ @#{res_name} = instance_variable_get(dym.first.to_sym)
1122
+ else
1123
+ raise ActiveRecord::RecordNotFound.new(msg)
1124
+ end
1125
+ end
1126
+
1127
+ # Starts as being just has_many columns, and will be augmented later with all the other columns
1128
+ cols = {#{hms_keys = []
1129
+ hms_headers.map do |hm|
1130
+ hms_keys << (assoc_name = (assoc = hm.first).name.to_s)
1131
+ "#{assoc_name.inspect} => [#{(assoc.options[:through] && !assoc.through_reflection).inspect}, #{assoc.klass.name}, #{hm[1].inspect}, #{hm[2].inspect}]"
1132
+ end.join(', ')}}
1133
+
1134
+ # %%% Why in the Canvas LMS app does ActionView::Helpers get cleared / reloaded, or otherwise lose access to #brick_grid ???
1135
+ # Possible fix if somewhere we can implement the #include with:
1136
+ # (ActiveSupport.const_defined?('Reloader') ? ActiveSupport : ActionDispatch)::Reloader.to_prepare do ... end
1137
+ # or
1138
+ # Rails.application.reloader.to_prepare do ... end
1139
+ self.class.class_exec { include ::Brick::Rails::FormTags } unless respond_to?(:brick_grid)
1140
+
1141
+ # Prepare the main content now so that we have a chance to become aware of any STI child classes represented in the rows returned.
1142
+ main_content = #{
1143
+ # Determine if we should render an N:M representation or the standard "mega_grid"
1144
+ taa = ::Brick.config.treat_as_associative&.fetch(table_name, nil)
1145
+ options = {}
1146
+ options[:prefix] = prefix unless prefix.blank?
1147
+ if taa.is_a?(String) || # Write out a constellation
1148
+ (taa.is_a?(Array) && (options[:axes] = taa[0..-2]) && (options[:dsl] = taa.last))
1149
+ representation = :constellation
1150
+ "brick_constellation(@#{res_name}, #{options.inspect}, bt_descrip: @_brick_bt_descrip, bts: bts)"
1151
+ elsif taa.is_a?(Symbol) # Write out a bezier representation
1152
+ "brick_bezier(@#{res_name}, #{options.inspect}, bt_descrip: @_brick_bt_descrip, bts: bts)"
1153
+ else # Write out the mega-grid
1154
+ representation = :grid
1155
+ "brick_grid(@#{res_name}, @_brick_sequence, @_brick_incl, @_brick_excl,
1156
+ cols, bt_descrip: @_brick_bt_descrip,
1157
+ poly_cols: poly_cols, bts: bts, hms_keys: #{hms_keys.inspect}, hms_cols: {#{hms_columns.join(', ')}})"
1158
+ end}
1106
1159
  %><%= if (children = model.descendants).present?
1107
1160
  child_links = children.map do |child|
1108
1161
  path = send(\"#\{child._brick_index}_path\") + \"?__#\{base_model.inheritance_column}=#\{child.name}\"
@@ -1112,7 +1165,7 @@ if (window.brickFontFamily) {
1112
1165
  end
1113
1166
  %><%= if (page_num = @#{res_name}&._brick_page_num)
1114
1167
  \"<tr><td colspan=\\\"#\{td_count}\\\">Page #\{page_num}</td></tr>\".html_safe
1115
- end %></table>#{template_link}<%
1168
+ end %></table><%
1116
1169
  if description.present? %><span class=\"__brick\"><%=
1117
1170
  description %></span><br><%
1118
1171
  end
@@ -1214,60 +1267,7 @@ end
1214
1267
  </div></div>
1215
1268
  #{::Brick::Rails.erd_markup(@_brick_model, prefix) if @_brick_model}
1216
1269
 
1217
- <%=# Consider getting the name from the association -- hm.first.name -- if a more \"friendly\" alias should be used for a screwy table name
1218
- # If the resource is missing, has the user simply created an inappropriately pluralised name for a table?
1219
- @#{res_name} ||= if (dym_list = instance_variables.reject do |entry|
1220
- entry.to_s.start_with?('@_') ||
1221
- ['@cache_hit', '@marked_for_same_origin_verification', '@view_renderer', '@view_flow', '@output_buffer', '@virtual_path'].include?(entry.to_s)
1222
- end).present?
1223
- msg = +\"Can't find resource \\\"#{res_name}\\\".\"
1224
- # Can't be sure otherwise of what is up, so check DidYouMean and offer a suggestion.
1225
- if (dym = DidYouMean::SpellChecker.new(dictionary: dym_list).correct('@#{res_name}')).present?
1226
- msg << \"\nIf you meant \\\"#\{found_dym = dym.first[1..-1]}\\\" then to avoid this message add this entry into inflections.rb:\n\"
1227
- msg << \" inflect.irregular '#{obj_name}', '#\{found_dym}'\"
1228
- puts
1229
- puts \"WARNING: #\{msg}\"
1230
- puts
1231
- @#{res_name} = instance_variable_get(dym.first.to_sym)
1232
- else
1233
- raise ActiveRecord::RecordNotFound.new(msg)
1234
- end
1235
- end
1236
-
1237
- # Starts as being just has_many columns, and will be augmented later with all the other columns
1238
- cols = {#{hms_keys = []
1239
- hms_headers.map do |hm|
1240
- hms_keys << (assoc_name = (assoc = hm.first).name.to_s)
1241
- "#{assoc_name.inspect} => [#{(assoc.options[:through] && !assoc.through_reflection).inspect}, #{assoc.klass.name}, #{hm[1].inspect}, #{hm[2].inspect}]"
1242
- end.join(', ')}}
1243
-
1244
- # %%% Why in the Canvas LMS app does ActionView::Helpers get cleared / reloaded, or otherwise lose access to #brick_grid ???
1245
- # Possible fix if somewhere we can implement the #include with:
1246
- # (ActiveSupport.const_defined?('Reloader') ? ActiveSupport : ActionDispatch)::Reloader.to_prepare do ... end
1247
- # or
1248
- # Rails.application.reloader.to_prepare do ... end
1249
- self.class.class_exec { include ::Brick::Rails::FormTags } unless respond_to?(:brick_grid)
1250
-
1251
- #{# Determine if we should render an N:M representation or the standard "mega_grid"
1252
- taa = ::Brick.config.treat_as_associative&.fetch(table_name, nil)
1253
- options = {}
1254
- options[:prefix] = prefix unless prefix.blank?
1255
- if taa.is_a?(String) || # Write out a constellation
1256
- (taa.is_a?(Array) && (options[:axes] = taa[0..-2]) && (options[:dsl] = taa.last))
1257
- representation = :constellation
1258
- "
1259
- brick_constellation(@#{res_name}, #{options.inspect}, bt_descrip: @_brick_bt_descrip, bts: bts)"
1260
- elsif taa.is_a?(Symbol) # Write out a bezier representation
1261
- "
1262
- brick_bezier(@#{res_name}, #{options.inspect}, bt_descrip: @_brick_bt_descrip, bts: bts)"
1263
- else # Write out the mega-grid
1264
- representation = :grid
1265
- "
1266
- brick_grid(@#{res_name}, @_brick_sequence, @_brick_incl, @_brick_excl,
1267
- cols, bt_descrip: @_brick_bt_descrip,
1268
- poly_cols: poly_cols, bts: bts, hms_keys: #{hms_keys.inspect}, hms_cols: {#{hms_columns.join(', ')}})"
1269
- end}
1270
- %>
1270
+ <%= main_content %>
1271
1271
 
1272
1272
  #{"<hr><%= link_to_brick(model, new: true, class: '__brick') %>" unless @_brick_model.is_view?}
1273
1273
  #{script}
@@ -1397,6 +1397,7 @@ s << \"\\n <br>\\n\"
1397
1397
  end
1398
1398
 
1399
1399
  when 'show', 'new', 'update'
1400
+ representation = :show
1400
1401
  +"<html>
1401
1402
  <head>
1402
1403
  #{css}
@@ -1582,8 +1583,79 @@ end}
1582
1583
  puts "Couldn't work with action #{args.first}"
1583
1584
  end
1584
1585
  end
1586
+
1587
+
1588
+ case representation
1589
+ when :grid
1590
+ inline << "<script<%= @_request.env['_brick_nonce'] %>>
1591
+ <%# Make column headers sort when clicked
1592
+ # %%% Create a smart javascript routine which can do this client-side %>
1593
+ [... document.getElementsByTagName(\"TH\")].forEach(function (th) {
1594
+ th.addEventListener(\"click\", function (e) {
1595
+ var xOrder,
1596
+ currentOrder;
1597
+ if (xOrder = this.getAttribute(\"x-order\")) {
1598
+ if ((currentOrder = changeout(location.href, \"_brick_order\")) === xOrder)
1599
+ xOrder = \"-\" + xOrder;
1600
+ location.href = changeout(location.href, \"_brick_order\", xOrder);
1601
+ }
1602
+ });
1603
+ });
1604
+ </script>"
1605
+ when :show
1606
+ inline << "<script<%= @_request.env['_brick_nonce'] %>>
1607
+ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1608
+ var origVal = getInpVal(),
1609
+ prevVal = origVal;
1610
+ var revert;
1611
+ if (inp.getAttribute(\"type\") == \"hidden\" || inp.getAttribute(\"type\") == \"submit\") return;
1612
+
1613
+ var svgTd = null;
1614
+ if ((revert = ((inp.tagName === \"SELECT\" && (svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild) ||
1615
+ ((svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild))
1616
+ ) && revert.tagName.toLowerCase() === \"svg\")
1617
+ revert.addEventListener(\"click\", function (e) {
1618
+ if (inp.type === \"checkbox\")
1619
+ inp.checked = origVal;
1620
+ else
1621
+ inp.value = origVal;
1622
+ revert.style.display = \"none\";
1623
+ if (inp._flatpickr)
1624
+ inp._flatpickr.setDate(origVal);
1625
+ else
1626
+ inp.focus();
1627
+ });
1628
+ inp.addEventListener(inp.type === \"checkbox\" ? \"change\" : \"input\", function (e) {
1629
+ if(inp.className.split(\" \").indexOf(\"check-validity\") > 0) {
1630
+ if (inp.checkValidity()) {
1631
+ prevVal = getInpVal();
1632
+ } else {
1633
+ inp.value = prevVal;
1634
+ }
1635
+ } else {
1636
+ // If this is the result of changing an hour or minute, keep the calendar open.
1637
+ // And if it was the result of selecting a date, the calendar can now close.
1638
+ if (inp._flatpickr &&
1639
+ // Test only for changes in the date portion of a date or datetime
1640
+ ((giv = getInpVal()) && (giv1 = giv.split(' ')[0])) !== (prevVal && prevVal.split(' ')[0]) &&
1641
+ giv1.indexOf(\":\") < 0 // (definitely not any part of a time thing)
1642
+ )
1643
+ inp._flatpickr.close();
1644
+ prevVal = getInpVal();
1645
+ }
1646
+ // Show or hide the revert button
1647
+ if (revert) revert.style.display = getInpVal() === origVal ? \"none\" : \"block\";
1648
+ });
1649
+ function getInpVal() {
1650
+ return inp.type === \"checkbox\" ? inp.checked : inp.value;
1651
+ }
1652
+ });
1653
+ </script>"
1654
+ end
1655
+
1656
+
1585
1657
  unless is_crosstab
1586
- inline << "
1658
+ inline << "#{template_link}
1587
1659
  <% if @_date_fields_present %>
1588
1660
  <link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css\">
1589
1661
  <style>
@@ -1708,69 +1780,6 @@ flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
1708
1780
  %></script>
1709
1781
  <% end %>
1710
1782
  "
1711
- end
1712
- if representation == :grid
1713
- inline << "<script<%= @_request.env['_brick_nonce'] %>>
1714
- <%# Make column headers sort when clicked
1715
- # %%% Create a smart javascript routine which can do this client-side %>
1716
- [... document.getElementsByTagName(\"TH\")].forEach(function (th) {
1717
- th.addEventListener(\"click\", function (e) {
1718
- var xOrder,
1719
- currentOrder;
1720
- if (xOrder = this.getAttribute(\"x-order\")) {
1721
- if ((currentOrder = changeout(location.href, \"_brick_order\")) === xOrder)
1722
- xOrder = \"-\" + xOrder;
1723
- location.href = changeout(location.href, \"_brick_order\", xOrder);
1724
- }
1725
- });
1726
- });
1727
- document.querySelectorAll(\"input, select\").forEach(function (inp) {
1728
- var origVal = getInpVal(),
1729
- prevVal = origVal;
1730
- var revert;
1731
- if (inp.getAttribute(\"type\") == \"hidden\" || inp.getAttribute(\"type\") == \"submit\") return;
1732
-
1733
- var svgTd = null;
1734
- if ((revert = ((inp.tagName === \"SELECT\" && (svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild) ||
1735
- ((svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild))
1736
- ) && revert.tagName.toLowerCase() === \"svg\")
1737
- revert.addEventListener(\"click\", function (e) {
1738
- if (inp.type === \"checkbox\")
1739
- inp.checked = origVal;
1740
- else
1741
- inp.value = origVal;
1742
- revert.style.display = \"none\";
1743
- if (inp._flatpickr)
1744
- inp._flatpickr.setDate(origVal);
1745
- else
1746
- inp.focus();
1747
- });
1748
- inp.addEventListener(inp.type === \"checkbox\" ? \"change\" : \"input\", function (e) {
1749
- if(inp.className.split(\" \").indexOf(\"check-validity\") > 0) {
1750
- if (inp.checkValidity()) {
1751
- prevVal = getInpVal();
1752
- } else {
1753
- inp.value = prevVal;
1754
- }
1755
- } else {
1756
- // If this is the result of changing an hour or minute, keep the calendar open.
1757
- // And if it was the result of selecting a date, the calendar can now close.
1758
- if (inp._flatpickr &&
1759
- // Test only for changes in the date portion of a date or datetime
1760
- ((giv = getInpVal()) && (giv1 = giv.split(' ')[0])) !== (prevVal && prevVal.split(' ')[0]) &&
1761
- giv1.indexOf(\":\") < 0 // (definitely not any part of a time thing)
1762
- )
1763
- inp._flatpickr.close();
1764
- prevVal = getInpVal();
1765
- }
1766
- // Show or hide the revert button
1767
- if (revert) revert.style.display = getInpVal() === origVal ? \"none\" : \"block\";
1768
- });
1769
- function getInpVal() {
1770
- return inp.type === \"checkbox\" ? inp.checked : inp.value;
1771
- }
1772
- });
1773
- </script>"
1774
1783
  end
1775
1784
  # puts "==============="
1776
1785
  # puts inline
@@ -7,7 +7,8 @@ module Brick::Rails::FormBuilder
7
7
  # @_date_fields_present - To include flatpickr date / time editor
8
8
  # @_json_fields_present - To include JSONEditor
9
9
  def brick_field(method, html_options = {}, val = nil, col = nil,
10
- bt = nil, bt_class = nil, bt_name = nil, bt_pair = nil)
10
+ bt = nil, bt_class = nil, bt_name = nil, bt_pair = nil,
11
+ is_readonly = nil)
11
12
  model = self.object.class
12
13
  col ||= model.columns_hash[method.to_s]
13
14
  out = +'<table><tr><td>'
@@ -20,8 +21,6 @@ module Brick::Rails::FormBuilder
20
21
  bt_name ||= bt[1].map { |x| x.first.name }.join('/')
21
22
  bt_pair ||= bt[1].first
22
23
 
23
- html_options[:prompt] = "Select #{bt_name}"
24
- out << self.select(method_sym, bt[3], { value: val || '^^^brick_NULL^^^' }, html_options)
25
24
  bt_obj = nil
26
25
  begin
27
26
  bt_obj = bt_class&.find_by(bt_pair[1] => val)
@@ -29,6 +28,10 @@ module Brick::Rails::FormBuilder
29
28
  # %%% Would be cool to indicate to the user that a subclass is missing.
30
29
  # Its name starts at: e.message.index('failed to locate the subclass: ') + 31
31
30
  end
31
+ html_options[:prompt] = "Select #{bt_name}"
32
+ out << (is_readonly ? (bt_obj&.brick_descrip || val.to_s) + '&nbsp;' :
33
+ self.select(method_sym, bt[3], { value: val || '^^^brick_NULL^^^' }, html_options)
34
+ )
32
35
  bt_link = if bt_obj
33
36
  bt_path = template.send(
34
37
  "#{bt_class.base_class._brick_index(:singular)}_path".to_sym,
@@ -58,6 +58,7 @@ module Brick::Rails::FormTags
58
58
  s << if (bt = bts[col_name])
59
59
  # Allow sorting for any BT except polymorphics
60
60
  x_order = " x-order=\"#{bt.first}\"" unless bt[2]
61
+ # binding.pry
61
62
  "#{x_order}>BT #{bt[1].map { |bt_pair| bt_pair.first.bt_link(bt.first) }.join(' ')}"
62
63
  else # Normal column
63
64
  col_name_humanised = klass.human_attribute_name(col_name, { default: col_name })
@@ -366,13 +367,14 @@ module Brick::Rails::FormTags
366
367
  </th>
367
368
  <td>
368
369
  "
369
- if pk_pos &&
370
+ if !pk_pos || bt ||
370
371
  # Allow new records to have a text-based primary key to be entered
371
- (!obj.new_record? || [:string, :text].exclude?(col.type))
372
- out << val.to_s
373
- else
372
+ (pk_pos && obj.new_record? && [:string, :text].include?(col.type))
374
373
  has_updatable_fields = true
375
- out << f.brick_field(k, html_options = {}, val, col, bt, bt_class, bt_name, bt_pair)
374
+ out << f.brick_field(k, html_options = {}, val, col, bt, bt_class, bt_name, bt_pair,
375
+ pk_pos && !obj.new_record?) # Cause it to be read-only if it's part of a primary key
376
+ else
377
+ out << val.to_s
376
378
  end
377
379
  out << "
378
380
  </td>
data/lib/brick/rails.rb CHANGED
@@ -27,7 +27,7 @@ module ::Brick::Rails
27
27
  (val && ::Brick.is_geography?(val))
28
28
  )
29
29
  )
30
- # MySQL's \"Internal Geometry Format\" and MSSQL's Geography are like WKB, but with an initial 4 bytes that indicates the SRID.
30
+ # MySQL's "Internal Geometry Format" and MSSQL's Geography are like WKB, but with an initial 4 bytes that indicates the SRID.
31
31
  if (srid = val&.[](0..3)&.unpack('I'))
32
32
  val = val.dup.force_encoding('BINARY')[4..-1].bytes
33
33
 
@@ -109,7 +109,7 @@ module ::Brick::Rails
109
109
  if ((signature = @image_signatures.find { |k, _v| val[0...k.length] == k }&.last) ||
110
110
  (val[0..3] == 'RIFF' && val[8..11] == 'WEBP' && binding.local_variable_set(:signature, 'webp'))) &&
111
111
  val.length < max_size
112
- "<img src=\"data:image/#{signature.last};base64,#{Base64.encode64(val)}\">"
112
+ "<img src=\"data:image/#{signature};base64,#{Base64.encode64(val)}\">"
113
113
  else
114
114
  descrip = "#{signature ? "#{signature} image" : 'Binary'}, #{val.length} bytes"
115
115
  no_escaped_html ? "< #{descrip} >" : "&lt;&nbsp;#{descrip}&nbsp;>"
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 252
8
+ TINY = 254
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
@@ -52,14 +52,14 @@ if ActiveRecord.version >= ::Gem::Version.new('4') && ActiveRecord.version < ::G
52
52
  [
53
53
  # Change 1 - Line 904
54
54
  ['build_joins(arel, joins_values.flatten) unless joins_values.empty?',
55
- "build_joins(arel, joins_values.flatten) unless joins_values.empty?
55
+ "build_joins(arel, joins_values.flatten) unless joins_values.empty?
56
56
  build_left_outer_joins(arel, left_outer_joins_values.flatten) unless left_outer_joins_values.empty?"
57
57
  ],
58
58
  # Change 2 - Line 992
59
59
  ["raise 'unknown class: %s' % join.class.name
60
60
  end
61
61
  end",
62
- "raise 'unknown class: %s' % join.class.name
62
+ "raise 'unknown class: %s' % join.class.name
63
63
  end
64
64
  end
65
65
 
@@ -927,12 +927,40 @@ if (is_postgres = (Object.const_defined?('PG::VERSION') || Gem::Specification.fi
927
927
  )
928
928
  end
929
929
 
930
+ # Allow ActiveRecord < 6.1 to work with Ruby 3.0 and later
931
+ if ActiveRecord.version < ::Gem::Version.new('6.0a') && ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('3.0')
932
+ ::Brick::Util._patch_require(
933
+ 'active_record/connection_adapters/abstract/database_statements.rb', '/activerecord',
934
+ [' def transaction(requires_new: nil, isolation: nil, joinable: true)',
935
+ " def transaction(options = {}, requires_new: nil, isolation: nil, joinable: true)
936
+ requires_new ||= options.fetch(:requires_new, nil)
937
+ isolation ||= options.fetch(:isolation, nil)"]
938
+ )
939
+ end
940
+
930
941
  require 'active_record'
931
942
  require 'active_record/relation'
932
943
  # To support adding left_outer_join
933
944
  require 'active_record/relation/query_methods' if ActiveRecord.version < ::Gem::Version.new('5')
934
945
  require 'rails/railtie' if ActiveRecord.version < ::Gem::Version.new('4.2')
935
946
 
947
+ # Allow ActiveRecord < 6.1 to work with Ruby 3.0 and later
948
+ if ActiveRecord.version < ::Gem::Version.new('6.0a') && ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('3.0')
949
+ ::ActiveRecord::Base.class_exec do
950
+ class << self
951
+ def transaction(options = {}, &block)
952
+ connection.transaction(**options, &block)
953
+ end
954
+ end
955
+ end
956
+ # ::Brick::Util._patch_require(
957
+ # 'active_record/transactions.rb', '/activerecord',
958
+ # [' connection.transaction(options, &block)',
959
+ # " connection.transaction(**options, &block)"],
960
+ # :Transactions
961
+ # )
962
+ end
963
+
936
964
  if Object.const_defined?('Rails')
937
965
  # Rake tasks
938
966
  class Railtie < ::Rails::Railtie
@@ -1295,6 +1323,18 @@ ActiveSupport.on_load(:active_record) do
1295
1323
  end
1296
1324
  end
1297
1325
 
1326
+ # Allow ActiveRecord < 6.1 to work with Ruby 3.1 and later
1327
+ if ActiveRecord.version < ::Gem::Version.new('6.1a') && ::Gem::Version.new(RUBY_VERSION) >= ::Gem::Version.new('3.1')
1328
+ require 'active_record/connection_adapters/abstract/transaction'
1329
+ ::ActiveRecord::ConnectionAdapters::Transaction.class_exec do
1330
+ alias _original_initialize initialize
1331
+ def initialize(connection, options, kwargs = {}, run_commit_callbacks: false)
1332
+ kwargs[:run_commit_callbacks] = run_commit_callbacks unless kwargs.key?(:run_commit_callbacks)
1333
+ _original_initialize(connection, options, **kwargs)
1334
+ end
1335
+ end
1336
+ end
1337
+
1298
1338
  if ActiveRecord.version < ::Gem::Version.new('6.1.4') &&
1299
1339
  Psych.method(:load).parameters.any? { |param| param.first == :key && param.last == :aliases }
1300
1340
  Psych.class_exec do
@@ -37,12 +37,12 @@ module Brick
37
37
  # Generate a list of viable models that can be chosen
38
38
  # First start with any existing models that have been defined ...
39
39
  existing_models = ActiveRecord::Base.descendants.each_with_object({}) do |m, s|
40
- s[m.table_name] = SeedModel.new(m.table_name, m, false) if !m.abstract_class? && !m.is_view? && m.table_exists?
40
+ s[(bc = m.base_class).name] = SeedModel.new(m.table_name, bc, false) if !m.abstract_class? && !m.is_view? && m.table_exists?
41
41
  end
42
42
  models = (existing_models.values +
43
43
  # ... then add models which can be auto-built by Brick
44
44
  relations.reject do |k, v|
45
- k.is_a?(Symbol) || (v.key?(:isView) && v[:isView] == true) || existing_models.key?(k)
45
+ k.is_a?(Symbol) || (v.key?(:isView) && v[:isView] == true) || existing_models.key?(v[:class_name])
46
46
  end.map { |k, v| SeedModel.new(k, v[:class_name].constantize, true) }
47
47
  ).sort { |a, b| a.to_s <=> b.to_s }
48
48
  if models.empty?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.252
4
+ version: 1.0.254
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits