brick 1.0.128 → 1.0.130
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +21 -8
- data/lib/brick/frameworks/rails/engine.rb +39 -22
- data/lib/brick/frameworks/rails/form_tags.rb +8 -1
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +2 -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: 902948e0d502bc9c1b604f3e99b975ab8c7d42c378888280d84dac6aef2aa7d0
|
4
|
+
data.tar.gz: 82988754dcae3ccc67eb5997531b3fa218ecf364f076ecf221fac201412baff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 780184ebc02c020389bc2239e115e885df056fa6895ed32bd35b5315f2e55f86deb679f2966e7290118bc54f4d50478b4240d7d77470d27a5902af22948d83f1
|
7
|
+
data.tar.gz: 39c37a9db2c7c392209491e1609f8ab4c2b64d27371452b60310d326bd462b5e653196697d0faf8f4bf801793400e073bf73f2ed72a38e9c66bd9b8e98d1e778
|
data/lib/brick/extensions.rb
CHANGED
@@ -148,7 +148,8 @@ module ActiveRecord
|
|
148
148
|
translations[parts[0..-2].join('.')] = klass
|
149
149
|
end
|
150
150
|
if klass&.column_names.exclude?(parts.last) &&
|
151
|
-
(klass = (orig_class = klass).reflect_on_association(possible_dsl = parts.
|
151
|
+
(klass = (orig_class = klass).reflect_on_association(possible_dsl = parts.last&.to_sym)&.klass)
|
152
|
+
parts.pop
|
152
153
|
if prefix.empty? # Custom columns start with an empty prefix
|
153
154
|
prefix << parts.shift until parts.empty?
|
154
155
|
end
|
@@ -162,6 +163,7 @@ module ActiveRecord
|
|
162
163
|
if emit_dsl
|
163
164
|
dsl3 << "[#{prefix[1..-1].map { |p| "#{p.to_s}." }.join if prefix.length > 1}#{bracket_name}]"
|
164
165
|
end
|
166
|
+
parts[-1] = column_names.first if parts[-1].nil? # No primary key to be found? Grab something to display!
|
165
167
|
members << parts
|
166
168
|
end
|
167
169
|
end
|
@@ -231,7 +233,8 @@ module ActiveRecord
|
|
231
233
|
if this_obj.is_a?(ActiveRecord::Base) && (obj_descrip = this_obj.class.brick_descrip(this_obj))
|
232
234
|
this_obj = obj_descrip
|
233
235
|
end
|
234
|
-
if
|
236
|
+
if Object.const_defined?('ActiveStorage') && this_obj.is_a?(::ActiveStorage::Filename) &&
|
237
|
+
this_obj.instance_variable_get(:@filename).nil?
|
235
238
|
this_obj.instance_variable_set(:@filename, '')
|
236
239
|
end
|
237
240
|
this_obj&.to_s || ''
|
@@ -741,12 +744,20 @@ module ActiveRecord
|
|
741
744
|
end
|
742
745
|
else
|
743
746
|
fk_col = (inv = hm.inverse_of)&.foreign_key || hm.foreign_key
|
744
|
-
|
747
|
+
# %%% Might only need hm.type and not the first part :)
|
748
|
+
poly_type = inv&.foreign_type || hm.type if hm.options.key?(:as)
|
745
749
|
pk = hm.klass.primary_key
|
746
750
|
(pk.is_a?(Array) ? pk.first : pk) || '*'
|
747
751
|
end
|
748
752
|
next unless count_column # %%% Would be able to remove this when multiple foreign keys to same destination becomes bulletproof
|
749
753
|
|
754
|
+
pri_tbl = hm.active_record
|
755
|
+
pri_key = hm.options[:primary_key] || pri_tbl.primary_key
|
756
|
+
unless hm.klass.column_names.include?(pri_key)
|
757
|
+
nix << k
|
758
|
+
next
|
759
|
+
end
|
760
|
+
|
750
761
|
tbl_alias = if is_mysql
|
751
762
|
"`b_r_#{hm.name}`"
|
752
763
|
elsif is_postgres
|
@@ -754,7 +765,6 @@ module ActiveRecord
|
|
754
765
|
else
|
755
766
|
"b_r_#{hm.name}"
|
756
767
|
end
|
757
|
-
pri_tbl = hm.active_record
|
758
768
|
pri_tbl_name = is_mysql ? "`#{pri_tbl.table_name}`" : "\"#{pri_tbl.table_name.gsub('.', '"."')}\""
|
759
769
|
pri_tbl_name = if is_mysql
|
760
770
|
"`#{pri_tbl.table_name}`"
|
@@ -765,10 +775,10 @@ module ActiveRecord
|
|
765
775
|
end
|
766
776
|
on_clause = []
|
767
777
|
hm_selects = if fk_col.is_a?(Array) # Composite key?
|
768
|
-
fk_col.each_with_index { |fk_col_part, idx| on_clause << "#{tbl_alias}.#{fk_col_part} = #{pri_tbl_name}.#{
|
778
|
+
fk_col.each_with_index { |fk_col_part, idx| on_clause << "#{tbl_alias}.#{fk_col_part} = #{pri_tbl_name}.#{pri_key[idx]}" }
|
769
779
|
fk_col.dup
|
770
780
|
else
|
771
|
-
on_clause << "#{tbl_alias}.#{fk_col} = #{pri_tbl_name}.#{
|
781
|
+
on_clause << "#{tbl_alias}.#{fk_col} = #{pri_tbl_name}.#{pri_key}"
|
772
782
|
[fk_col]
|
773
783
|
end
|
774
784
|
if poly_type
|
@@ -864,6 +874,9 @@ JOIN (SELECT #{hm_selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', '
|
|
864
874
|
def brick_list
|
865
875
|
pks = klass.primary_key.is_a?(String) ? [klass.primary_key] : klass.primary_key
|
866
876
|
selects = pks.each_with_object([]) { |pk, s| s << pk unless s.include?(pk) }
|
877
|
+
# ActiveStorage compatibility
|
878
|
+
selects << 'service_name' if klass.name == 'ActiveStorage::Blob' && ActiveStorage::Blob.columns_hash.key?('service_name')
|
879
|
+
selects << 'blob_id' if klass.name == 'ActiveStorage::Attachment' && ActiveStorage::Attachment.columns_hash.key?('blob_id')
|
867
880
|
pieces, my_dsl = klass.brick_parse_dsl(join_array = ::Brick::JoinArray.new, [], translations = {}, false, nil, true)
|
868
881
|
brick_select(
|
869
882
|
where_values_hash, selects, nil, translations, join_array,
|
@@ -1866,7 +1879,7 @@ class Object
|
|
1866
1879
|
# Convert any Filename objects with nil into an empty string so that #encode can be called on them
|
1867
1880
|
new_obj.serializable_hash.each do |k, v|
|
1868
1881
|
new_obj.send("#{k}=", ActiveStorage::Filename.new('')) if v.is_a?(ActiveStorage::Filename) && !v.instance_variable_get(:@filename)
|
1869
|
-
end
|
1882
|
+
end if Object.const_defined?('ActiveStorage')
|
1870
1883
|
end
|
1871
1884
|
instance_variable_set("@#{singular_table_name}".to_sym, new_obj)
|
1872
1885
|
end
|
@@ -2438,7 +2451,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
2438
2451
|
singular = rel_name.last
|
2439
2452
|
end
|
2440
2453
|
name_parts = if (tnp = ::Brick.config.table_name_prefixes
|
2441
|
-
|
2454
|
+
&.find { |k1, _v1| singular.start_with?(k1) && singular.length > k1.length }
|
2442
2455
|
).present?
|
2443
2456
|
v[:auto_prefixed_schema] = tnp.first
|
2444
2457
|
v[:resource] = rel_name.last[(tnp_length = tnp.first.length)..-1]
|
@@ -58,7 +58,7 @@ module Brick
|
|
58
58
|
'(Add RGeo gem to parse geometry detail)'
|
59
59
|
end
|
60
60
|
when :binary
|
61
|
-
::Brick::Rails.display_binary(val)
|
61
|
+
::Brick::Rails.display_binary(val)
|
62
62
|
else
|
63
63
|
if col_type
|
64
64
|
::Brick::Rails::FormBuilder.hide_bcrypt(val, col_type == :xml)
|
@@ -69,8 +69,12 @@ module Brick
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def display_binary(val)
|
72
|
+
return unless val
|
73
|
+
|
72
74
|
@image_signatures ||= { (+"\xFF\xD8\xFF\xEE").force_encoding('ASCII-8BIT') => 'jpeg',
|
73
75
|
(+"\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46\x00\x01").force_encoding('ASCII-8BIT') => 'jpeg',
|
76
|
+
(+"\xFF\xD8\xFF\xDB").force_encoding('ASCII-8BIT') => 'jpeg',
|
77
|
+
(+"\xFF\xD8\xFF\xE1").force_encoding('ASCII-8BIT') => 'jpeg',
|
74
78
|
(+"\x89PNG\r\n\x1A\n").force_encoding('ASCII-8BIT') => 'png',
|
75
79
|
'<svg' => 'svg+xml', # %%% Not yet very good detection for SVG
|
76
80
|
(+'BM').force_encoding('ASCII-8BIT') => 'bmp',
|
@@ -90,7 +94,8 @@ module Brick
|
|
90
94
|
val = val[object_start...object_start + real_object_size]
|
91
95
|
end
|
92
96
|
|
93
|
-
if (signature = @image_signatures.find { |k, _v| val[0...k.length] == k })
|
97
|
+
if (signature = @image_signatures.find { |k, _v| val[0...k.length] == k }) ||
|
98
|
+
(val[0..3] == 'RIFF' && val[8..11] == 'WEBP' && (signature = 'webp'))
|
94
99
|
if val.length < 500_000
|
95
100
|
"<img src=\"data:image/#{signature.last};base64,#{Base64.encode64(val)}\">"
|
96
101
|
else
|
@@ -647,7 +652,9 @@ window.addEventListener(\"popstate\", linkSchemas);
|
|
647
652
|
else
|
648
653
|
hm_assoc.active_record.name
|
649
654
|
end
|
650
|
-
|
655
|
+
# %%% Might only need hm_assoc.type and not the first part :)
|
656
|
+
type_col = hm_assoc.inverse_of&.foreign_type || hm_assoc.type
|
657
|
+
keys << [type_col, poly_type]
|
651
658
|
end
|
652
659
|
keys.to_h
|
653
660
|
end
|
@@ -1290,7 +1297,7 @@ erDiagram
|
|
1290
1297
|
</head>
|
1291
1298
|
<body>
|
1292
1299
|
<div id=\"titleBox\"><div id=\"titleSticky\">
|
1293
|
-
<p style=\"color: green\"><%= notice %></p>#{"
|
1300
|
+
<p style=\"color: green\"><%= notice if request.respond_to?(:flash) %></p>#{"
|
1294
1301
|
#{schema_options}" if schema_options}
|
1295
1302
|
<select id=\"tbl\">#{table_options}</select>
|
1296
1303
|
<table id=\"resourceName\"><tr>
|
@@ -1411,7 +1418,8 @@ end
|
|
1411
1418
|
brick_grid(@#{table_name}, @_brick_bt_descrip, @_brick_sequence, @_brick_incl, @_brick_excl,
|
1412
1419
|
cols, poly_cols, bts, #{hms_keys.inspect}, {#{hms_columns.join(', ')}}) %>
|
1413
1420
|
|
1414
|
-
#{"<hr><%= link_to
|
1421
|
+
#{"<hr><%= link_to(\"New #{new_path_name = "new_#{path_obj_name}_path"
|
1422
|
+
obj_name}\", #{new_path_name}) if respond_to?(:#{new_path_name}) %>" unless @_brick_model.is_view?}
|
1415
1423
|
#{script}
|
1416
1424
|
</body>
|
1417
1425
|
</html>
|
@@ -1423,7 +1431,7 @@ end
|
|
1423
1431
|
# Must load all models, and then find what table names are represented
|
1424
1432
|
# Easily could be multiple files involved (STI for instance)
|
1425
1433
|
+"#{css}
|
1426
|
-
<p style=\"color: green\"><%= notice %></p>#{"
|
1434
|
+
<p style=\"color: green\"><%= notice if request.respond_to?(:flash) %></p>#{"
|
1427
1435
|
#{schema_options}" if schema_options}
|
1428
1436
|
<select id=\"tbl\">#{table_options}</select>
|
1429
1437
|
<h1>Status</h1>
|
@@ -1473,7 +1481,7 @@ end
|
|
1473
1481
|
when 'orphans'
|
1474
1482
|
if is_orphans
|
1475
1483
|
+"#{css}
|
1476
|
-
<p style=\"color: green\"><%= notice %></p>#{"
|
1484
|
+
<p style=\"color: green\"><%= notice if request.respond_to?(:flash) %></p>#{"
|
1477
1485
|
#{schema_options}" if schema_options}
|
1478
1486
|
<select id=\"tbl\">#{table_options}</select>
|
1479
1487
|
<h1>Orphans<%= \" for #\{}\" if false %></h1>
|
@@ -1520,7 +1528,7 @@ end
|
|
1520
1528
|
c23.141-70.188,89.141-120.906,167.063-120.906c97.25,0,176,78.813,176,176C511.828,227.078,404.391,119.641,271.844,119.641z\" />
|
1521
1529
|
</svg>
|
1522
1530
|
|
1523
|
-
<p style=\"color: green\"><%= notice %></p>#{"
|
1531
|
+
<p style=\"color: green\"><%= notice if request.respond_to?(:flash) %></p>#{"
|
1524
1532
|
#{schema_options}" if schema_options}
|
1525
1533
|
<select id=\"tbl\">#{table_options}</select>
|
1526
1534
|
<table><td><h1><%= page_title %></h1></td>
|
@@ -1555,14 +1563,13 @@ end
|
|
1555
1563
|
%><%= link_to \"(See all #\{model_name.pluralize})\", see_all_path %>
|
1556
1564
|
#{erd_markup}
|
1557
1565
|
<% if obj
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
end
|
1566
|
+
# path_options = [obj.#{pk}]
|
1567
|
+
# path_options << { '_brick_schema': } if
|
1568
|
+
options = {}
|
1569
|
+
if ::Brick.config.path_prefix
|
1570
|
+
path_helper = obj.new_record? ? #{model_name}._brick_index : #{model_name}._brick_index(:singular)
|
1571
|
+
options[:url] = send(\"#\{path_helper}_path\".to_sym, obj)
|
1572
|
+
end
|
1566
1573
|
%>
|
1567
1574
|
<br><br>
|
1568
1575
|
<%= form_for(obj.becomes(#{model_name}), options) do |f| %>
|
@@ -1570,11 +1577,11 @@ end
|
|
1570
1577
|
<% has_fields = false
|
1571
1578
|
@#{obj_name}.attributes.each do |k, val|
|
1572
1579
|
next if !(col = #{model_name}.columns_hash[k]) ||
|
1573
|
-
(#{(pk || []).inspect}.include?(k) && !bts.key?(k)) ||
|
1580
|
+
(#{(pk.map(&:to_s) || []).inspect}.include?(k) && !bts.key?(k)) ||
|
1574
1581
|
::Brick.config.metadata_columns.include?(k) %>
|
1575
1582
|
<tr>
|
1576
1583
|
<th class=\"show-field\"<%= \" title=\\\"#\{col.comment}\\\"\".html_safe if col.respond_to?(:comment) && !col.comment.blank? %>>
|
1577
|
-
|
1584
|
+
<% has_fields = true
|
1578
1585
|
if (bt = bts[k])
|
1579
1586
|
# Add a final member in this array with descriptive options to be used in <select> drop-downs
|
1580
1587
|
bt_name = bt[1].map { |x| x.first.name }.join('/')
|
@@ -1627,7 +1634,11 @@ end
|
|
1627
1634
|
<% else %>
|
1628
1635
|
<tr><td colspan=\"2\">(No displayable fields)</td></tr>
|
1629
1636
|
<% end %>
|
1630
|
-
</table
|
1637
|
+
</table>#{
|
1638
|
+
"<%= binary = begin
|
1639
|
+
::Brick::Rails.display_binary(obj&.blob&.download)&.html_safe
|
1640
|
+
rescue
|
1641
|
+
end %>" if model_name == 'ActiveStorage::Attachment'}
|
1631
1642
|
<% end %>
|
1632
1643
|
|
1633
1644
|
#{unless args.first == 'new'
|
@@ -1660,6 +1671,12 @@ end
|
|
1660
1671
|
# In order to apply DSL properly, evaluate this HO the other way around as if it were as a BT
|
1661
1672
|
collection = assoc.klass.where(assoc.foreign_key => @#{obj_name}.#{pk})
|
1662
1673
|
collection = collection.instance_exec(&assoc.scopes.first) if assoc.scopes.present?
|
1674
|
+
if assoc.klass.name == 'ActiveStorage::Attachment'
|
1675
|
+
br_descrip = begin
|
1676
|
+
::Brick::Rails.display_binary(obj.send(assoc.name)&.blob&.download)&.html_safe
|
1677
|
+
rescue
|
1678
|
+
end
|
1679
|
+
end
|
1663
1680
|
else
|
1664
1681
|
collection = @#{obj_name}.#{hm_name}
|
1665
1682
|
end
|
@@ -1677,9 +1694,9 @@ end
|
|
1677
1694
|
<tr><td>(none)</td></tr>
|
1678
1695
|
<% else
|
1679
1696
|
collection2.each do |#{hm_singular_name}| %>
|
1680
|
-
<tr><td><%= br_descrip
|
1681
|
-
|
1682
|
-
|
1697
|
+
<tr><td><%= br_descrip ||= #{hm_singular_name}.brick_descrip(
|
1698
|
+
descrip_cols&.first&.map { |col| #{hm_singular_name}.send(col.last) }
|
1699
|
+
)
|
1683
1700
|
link_to(br_descrip, #{hm.first.klass._brick_index(:singular)}_path(slashify(#{obj_pk}))) %></td></tr>
|
1684
1701
|
<% end %>
|
1685
1702
|
<% end %>
|
@@ -115,7 +115,14 @@ module Brick::Rails::FormTags
|
|
115
115
|
if col[2] == 'HO'
|
116
116
|
descrips = bt_descrip[col_name.to_sym][hm_klass]
|
117
117
|
if (ho_id = (ho_id_col = descrips.last).map { |id_col| obj.send(id_col.to_sym) })&.first
|
118
|
-
ho_txt = hm_klass.
|
118
|
+
ho_txt = if hm_klass.name == 'ActiveStorage::Attachment'
|
119
|
+
begin
|
120
|
+
::Brick::Rails.display_binary(obj.send(col[3])&.blob&.download)&.html_safe
|
121
|
+
rescue
|
122
|
+
end
|
123
|
+
else
|
124
|
+
hm_klass.brick_descrip(obj, descrips[0..-2].map { |id| obj.send(id.last[0..62]) }, ho_id_col)
|
125
|
+
end
|
119
126
|
out << link_to(ho_txt, send("#{hm_klass.base_class._brick_index(:singular)}_path".to_sym, ho_id))
|
120
127
|
end
|
121
128
|
else
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -1661,7 +1661,8 @@ module ActiveRecord
|
|
1661
1661
|
relation.brick_links[link_path] = if child.table.is_a?(Arel::Nodes::TableAlias)
|
1662
1662
|
child.table.right
|
1663
1663
|
else
|
1664
|
-
result.first&.left&.table_alias || child.table_name
|
1664
|
+
# Was: result.first&.left&.table_alias || child.table_name
|
1665
|
+
child.table.table_alias || child.table_name
|
1665
1666
|
end
|
1666
1667
|
end
|
1667
1668
|
result
|
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.130
|
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-
|
11
|
+
date: 2023-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|