brick 1.0.42 → 1.0.45
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/extensions.rb +27 -16
- data/lib/brick/frameworks/rails/engine.rb +53 -29
- data/lib/brick/version_number.rb +1 -1
- data/lib/generators/brick/install_generator.rb +2 -2
- 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: 678e1295006174594606dc731cd650afa60d2cc727be08bd416c9503faeb1ca4
|
4
|
+
data.tar.gz: b00802df45b7e388523b29cfab38feaaaf7c61d057cf509c71a6a08860373b15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7962bbc61bd43b68062d188ac3565e38f4840d52ca76b4c675e0da55d213104f13e007578658441359323899ed881d10497bb8285384abe42a2d15bd9c26b64b
|
7
|
+
data.tar.gz: 449e74d3ab9558eed77c89aac5a871927ed0842fc043c910d04d1cca29221508332a7def78940ed67048a29e4384576aa8a176beb117c0bc7ff8a48a87f64af6
|
data/lib/brick/extensions.rb
CHANGED
@@ -274,7 +274,6 @@ module ActiveRecord
|
|
274
274
|
table = table.left
|
275
275
|
end
|
276
276
|
(_brick_chains[table._arel_table_type] ||= []) << (alias_name || table.table_alias || table.name)
|
277
|
-
# puts "YES! #{self.object_id}"
|
278
277
|
end
|
279
278
|
# rubocop:enable Style/IdenticalConditionalBranches
|
280
279
|
when Arel::Table # Table
|
@@ -286,9 +285,9 @@ module ActiveRecord
|
|
286
285
|
# Spin up an empty set of Brick alias name chains at the start
|
287
286
|
@_brick_chains = {}
|
288
287
|
# The left side is the "FROM" table
|
289
|
-
# names += _recurse_arel(piece.left)
|
290
288
|
names << (this_name = [piece.left._arel_table_type, (piece.left.table_alias || piece.left.name)])
|
291
|
-
|
289
|
+
# # Do not currently need the root "FROM" table in our list of chains
|
290
|
+
# (_brick_chains[this_name.first] ||= []) << this_name.last
|
292
291
|
# The right side is an array of all JOINs
|
293
292
|
piece.right.each { |join| names << _recurse_arel(join) }
|
294
293
|
end
|
@@ -354,6 +353,7 @@ module ActiveRecord
|
|
354
353
|
next if bt[2] # Polymorphic?
|
355
354
|
|
356
355
|
# join_array will receive this relation name when calling #brick_parse_dsl
|
356
|
+
# binding.pry if bt.length > 2
|
357
357
|
bt_descrip[bt.first] = if bt[1].is_a?(Array)
|
358
358
|
bt[1].each_with_object({}) { |bt_class, s| s[bt_class] = bt_class.brick_parse_dsl(join_array, bt.first, translations, true) }
|
359
359
|
else
|
@@ -364,7 +364,12 @@ module ActiveRecord
|
|
364
364
|
hms.each do |k, hm|
|
365
365
|
next if skip_klass_hms.key?(k)
|
366
366
|
|
367
|
-
|
367
|
+
if hm.macro == :has_one
|
368
|
+
# For our purposes a :has_one is similar enough to a :belongs_to that we can just join forces
|
369
|
+
bt_descrip[k] = { hm.klass => hm.klass.brick_parse_dsl(join_array, k, translations) }
|
370
|
+
else # Standard :has_many
|
371
|
+
hm_counts[k] = hm
|
372
|
+
end
|
368
373
|
end
|
369
374
|
end
|
370
375
|
|
@@ -650,10 +655,11 @@ class Object
|
|
650
655
|
private
|
651
656
|
|
652
657
|
def build_model(schema_name, inheritable_name, model_name, singular_table_name, table_name, relations, matching)
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
658
|
+
if ::Brick.config.schema_behavior[:multitenant] && Object.const_defined?('Apartment') &&
|
659
|
+
schema_name == Apartment.default_schema
|
660
|
+
relation = relations["#{schema_name}.#{matching}"]
|
661
|
+
end
|
662
|
+
full_name = if relation || schema_name.blank?
|
657
663
|
inheritable_name || model_name
|
658
664
|
else # Prefix the schema to the table name + prefix the schema namespace to the class name
|
659
665
|
schema_module = if schema_name.instance_of?(Module) # from an auto-STI namespace?
|
@@ -749,10 +755,10 @@ class Object
|
|
749
755
|
if assoc[:is_bt]
|
750
756
|
invs = invs.first # Just do the first one of what would be multiple identical polymorphic belongs_to
|
751
757
|
else
|
752
|
-
invs.each { |inv| build_bt_or_hm(
|
758
|
+
invs.each { |inv| build_bt_or_hm(full_name, relations, relation, hmts, assoc, inverse_assoc_name, inv, code) }
|
753
759
|
end
|
754
760
|
end
|
755
|
-
build_bt_or_hm(
|
761
|
+
build_bt_or_hm(full_name, relations, relation, hmts, assoc, inverse_assoc_name, invs, code) unless invs.is_a?(Array)
|
756
762
|
hmts
|
757
763
|
end
|
758
764
|
# # Not NULLables
|
@@ -804,7 +810,7 @@ class Object
|
|
804
810
|
[built_model, code]
|
805
811
|
end
|
806
812
|
|
807
|
-
def build_bt_or_hm(
|
813
|
+
def build_bt_or_hm(full_name, relations, relation, hmts, assoc, inverse_assoc_name, inverse_table, code)
|
808
814
|
singular_table_name = inverse_table&.singularize
|
809
815
|
options = {}
|
810
816
|
macro = if assoc[:is_bt]
|
@@ -826,8 +832,14 @@ class Object
|
|
826
832
|
end
|
827
833
|
if (inverse = assoc[:inverse])
|
828
834
|
inverse_assoc_name, _x = _brick_get_hm_assoc_name(relations[inverse_table], inverse)
|
829
|
-
|
830
|
-
if
|
835
|
+
# If it's multitenant with something like: public.____ ...
|
836
|
+
if (it_parts = inverse_table.split('.')).length > 1 &&
|
837
|
+
::Brick.config.schema_behavior[:multitenant] && Object.const_defined?('Apartment') &&
|
838
|
+
it_parts.first == Apartment.default_schema
|
839
|
+
it_parts.shift # ... then ditch the generic schema name
|
840
|
+
end
|
841
|
+
has_ones = ::Brick.config.has_ones&.fetch(it_parts.join('/').singularize.camelize, nil)
|
842
|
+
if has_ones&.key?(singular_inv_assoc_name = ActiveSupport::Inflector.singularize(inverse_assoc_name.tr('.', '_')))
|
831
843
|
inverse_assoc_name = if has_ones[singular_inv_assoc_name]
|
832
844
|
need_inverse_of = true
|
833
845
|
has_ones[singular_inv_assoc_name]
|
@@ -838,7 +850,6 @@ class Object
|
|
838
850
|
end
|
839
851
|
:belongs_to
|
840
852
|
else
|
841
|
-
# need_class_name = ActiveSupport::Inflector.singularize(assoc_name) == ActiveSupport::Inflector.singularize(table_name.underscore)
|
842
853
|
# Are there multiple foreign keys out to the same table?
|
843
854
|
assoc_name, need_class_name = _brick_get_hm_assoc_name(relation, assoc)
|
844
855
|
if assoc.key?(:polymorphic)
|
@@ -846,8 +857,8 @@ class Object
|
|
846
857
|
else
|
847
858
|
need_fk = "#{ActiveSupport::Inflector.singularize(assoc[:inverse][:inverse_table].split('.').last)}_id" != assoc[:fk]
|
848
859
|
end
|
849
|
-
|
850
|
-
if
|
860
|
+
has_ones = ::Brick.config.has_ones&.fetch(full_name, nil)
|
861
|
+
if has_ones&.key?(singular_assoc_name = ActiveSupport::Inflector.singularize(assoc_name.tr('.', '_')))
|
851
862
|
assoc_name = if (custom_assoc_name = has_ones[singular_assoc_name])
|
852
863
|
need_class_name = custom_assoc_name != singular_assoc_name
|
853
864
|
custom_assoc_name
|
@@ -129,7 +129,11 @@ module Brick
|
|
129
129
|
"#{assoc_name}\n"
|
130
130
|
end
|
131
131
|
else # has_one
|
132
|
-
|
132
|
+
# 0..62 because Postgres column names are limited to 63 characters
|
133
|
+
"<%= descrips = @_brick_bt_descrip[#{hm.first.inspect}][ho_class = #{hm[1].klass.name}]
|
134
|
+
ho_txt = ho_class.brick_descrip(#{obj_name}, descrips[0..-2].map { |id| #{obj_name}.send(id.last[0..62]) }, (ho_id_col = descrips.last))
|
135
|
+
ho_id = ho_id_col.map { |id_col| #{obj_name}.send(id_col.to_sym) }
|
136
|
+
ho_id&.first ? link_to(ho_txt, send(\"#\{ho_class.base_class.name.underscore.tr('/', '_')\}_path\".to_sym, ho_id)) : ho_txt %>\n"
|
133
137
|
end
|
134
138
|
when 'show', 'update'
|
135
139
|
hm_stuff << if hm_fk_name
|
@@ -164,10 +168,10 @@ module Brick
|
|
164
168
|
}
|
165
169
|
|
166
170
|
#headerTop {
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
+
position: sticky;
|
172
|
+
top: 0px;
|
173
|
+
background-color: white;
|
174
|
+
z-index: 1;
|
171
175
|
}
|
172
176
|
table {
|
173
177
|
border-collapse: collapse;
|
@@ -236,6 +240,10 @@ a.big-arrow {
|
|
236
240
|
.dimmed {
|
237
241
|
background-color: #C0C0C0;
|
238
242
|
}
|
243
|
+
.orphan {
|
244
|
+
color: red;
|
245
|
+
white-space: nowrap;
|
246
|
+
}
|
239
247
|
|
240
248
|
#revertTemplate {
|
241
249
|
display: none;
|
@@ -251,16 +259,16 @@ input+svg.revert {
|
|
251
259
|
top: 0.5em;
|
252
260
|
}
|
253
261
|
|
254
|
-
|
262
|
+
.update {
|
263
|
+
position: sticky;
|
264
|
+
right: 1em;
|
265
|
+
float: right;
|
255
266
|
background-color: #004998;
|
256
267
|
color: #FFF;
|
257
268
|
}
|
258
|
-
|
259
|
-
text-align: right;
|
260
|
-
}
|
269
|
+
|
261
270
|
</style>
|
262
|
-
<%
|
263
|
-
is_includes_dates = nil
|
271
|
+
<% is_includes_dates = nil
|
264
272
|
|
265
273
|
def is_bcrypt?(val)
|
266
274
|
val.is_a?(String) && val.length == 60 && val.start_with?('$2a$')
|
@@ -334,7 +342,13 @@ window.addEventListener(\"pageshow\", function() {
|
|
334
342
|
});
|
335
343
|
|
336
344
|
if (tblSelect) { // Always present
|
337
|
-
|
345
|
+
var i = schemaSelect ? 1 : 0,
|
346
|
+
changeoutList = changeout(location.href);
|
347
|
+
for (; i < changeoutList.length; ++i) {
|
348
|
+
tblSelect.value = changeoutList[i];
|
349
|
+
if (tblSelect.value !== \"\") break;
|
350
|
+
}
|
351
|
+
|
338
352
|
tblSelect.addEventListener(\"change\", function () {
|
339
353
|
var lhr = changeout(location.href, null, this.value);
|
340
354
|
if (brickSchema)
|
@@ -357,7 +371,7 @@ function changeout(href, param, value, trimAfter) {
|
|
357
371
|
}
|
358
372
|
if (trimAfter) {
|
359
373
|
var pathParts = hrefParts[0].split(\"/\");
|
360
|
-
while (pathParts.lastIndexOf(trimAfter)
|
374
|
+
while (pathParts.lastIndexOf(trimAfter) !== pathParts.length - 1) pathParts.pop();
|
361
375
|
hrefParts[0] = pathParts.join(\"/\");
|
362
376
|
}
|
363
377
|
var params = hrefParts.length > 1 ? hrefParts[1].split(\"&\") : [];
|
@@ -569,11 +583,11 @@ if (headerTop) {
|
|
569
583
|
else
|
570
584
|
bt_txt = (bt_class = bt[1].first.first).brick_descrip(
|
571
585
|
# 0..62 because Postgres column names are limited to 63 characters
|
572
|
-
#{obj_name}, (descrips = @_brick_bt_descrip[bt.first][bt_class])[0..-2].map { |
|
586
|
+
#{obj_name}, (descrips = @_brick_bt_descrip[bt.first][bt_class])[0..-2].map { |id| #{obj_name}.send(id.last[0..62]) }, (bt_id_col = descrips.last)
|
573
587
|
)
|
574
|
-
bt_txt ||= \"
|
575
|
-
bt_id = #{obj_name}.send(
|
576
|
-
<%= bt_id ? link_to(bt_txt, send(\"#\{bt_class.base_class.name.underscore.tr('/', '_')\}_path\".to_sym, bt_id)) : bt_txt %>
|
588
|
+
bt_txt ||= \"<span class=\\\"orphan\\\"><< Orphaned ID: #\{val} >></span>\".html_safe if val
|
589
|
+
bt_id = bt_id_col.map { |id_col| #{obj_name}.send(id_col.to_sym) } %>
|
590
|
+
<%= bt_id&.first ? link_to(bt_txt, send(\"#\{bt_class.base_class.name.underscore.tr('/', '_')\}_path\".to_sym, bt_id)) : bt_txt %>
|
577
591
|
<%#= Previously was: bt_obj = bt[1].first.first.find_by(bt[2] => val); link_to(bt_obj.brick_descrip, send(\"#\{bt[1].first.first.name.underscore\}_path\".to_sym, bt_obj.send(bt[1].first.first.primary_key.to_sym))) if bt_obj %>
|
578
592
|
<% end %>
|
579
593
|
<% else %>
|
@@ -680,22 +694,21 @@ end
|
|
680
694
|
<%= if (bt_obj = bt_class&.find_by(bt_pair[1] => val))
|
681
695
|
link_to('⇛', send(\"#\{bt_class.base_class.name.underscore.tr('/', '_')\}_path\".to_sym, bt_obj.send(bt_class.primary_key.to_sym)), { class: 'show-arrow' })
|
682
696
|
elsif val
|
683
|
-
\"<span>Orphaned ID: #\{val}</span>\".html_safe
|
697
|
+
\"<span class=\\\"orphan\\\">Orphaned ID: #\{val}</span>\".html_safe
|
684
698
|
end %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
|
685
|
-
<% else
|
699
|
+
<% else
|
700
|
+
html_options = {}
|
701
|
+
html_options[:class] = 'dimmed' unless val
|
702
|
+
case (col_type = #{model_name}.column_for_attribute(k).type)
|
686
703
|
when :string, :text %>
|
687
704
|
<% if is_bcrypt?(val) # || .readonly? %>
|
688
705
|
<%= hide_bcrypt(val, 1000) %>
|
689
706
|
<% else %>
|
690
|
-
<div class=\"wide-input\"><%= f.text_field
|
707
|
+
<div class=\"wide-input\"><%= f.text_field(k.to_sym, html_options) %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg></div>
|
691
708
|
<% end %>
|
692
709
|
<% when :boolean %>
|
693
710
|
<%= f.check_box k.to_sym %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
|
694
|
-
<% when :integer, :decimal, :float
|
695
|
-
# What happens when keys are UUID?
|
696
|
-
# Postgres naturally uses the +uuid_generate_v4()+ function from the uuid-ossp extension
|
697
|
-
# If it's not yet enabled then: enable_extension 'uuid-ossp'
|
698
|
-
# ActiveUUID gem created a new :uuid type %>
|
711
|
+
<% when :integer, :decimal, :float %>
|
699
712
|
<%= if col_type == :integer
|
700
713
|
f.text_field k.to_sym, { pattern: '\\d*', class: 'check-validity' }
|
701
714
|
else
|
@@ -704,6 +717,12 @@ end
|
|
704
717
|
<% when *dt_pickers.keys
|
705
718
|
is_includes_dates = true %>
|
706
719
|
<%= f.text_field k.to_sym, { class: dt_pickers[col_type] } %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
|
720
|
+
<% when :uuid %>
|
721
|
+
<%=
|
722
|
+
# Postgres naturally uses the +uuid_generate_v4()+ function from the uuid-ossp extension
|
723
|
+
# If it's not yet enabled then: enable_extension 'uuid-ossp'
|
724
|
+
# ActiveUUID gem created a new :uuid type
|
725
|
+
val %>
|
707
726
|
<% when :binary, :primary_key %>
|
708
727
|
<% end %>
|
709
728
|
<% end %>
|
@@ -711,7 +730,7 @@ end
|
|
711
730
|
</tr>
|
712
731
|
<% end
|
713
732
|
if has_fields %>
|
714
|
-
<tr><td colspan=\"2\"
|
733
|
+
<tr><td colspan=\"2\"><%= f.submit({ class: 'update' }) %></td></tr>
|
715
734
|
<% else %>
|
716
735
|
<tr><td colspan=\"2\">(No displayable fields)</td></tr>
|
717
736
|
<% end %>
|
@@ -757,6 +776,7 @@ end
|
|
757
776
|
<script>
|
758
777
|
flatpickr(\".datepicker\");
|
759
778
|
flatpickr(\".datetimepicker\", {enableTime: true});
|
779
|
+
flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
|
760
780
|
</script>
|
761
781
|
<% end %>
|
762
782
|
<script>
|
@@ -772,8 +792,11 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
|
|
772
792
|
inp.checked = origVal;
|
773
793
|
else
|
774
794
|
inp.value = origVal;
|
775
|
-
|
776
|
-
|
795
|
+
revert.style.display = \"none\";
|
796
|
+
if (inp._flatpickr)
|
797
|
+
inp._flatpickr.setDate(origVal);
|
798
|
+
else
|
799
|
+
inp.focus();
|
777
800
|
});
|
778
801
|
inp.addEventListener(inp.type === \"checkbox\" ? \"change\" : \"input\", function (e) {
|
779
802
|
if(inp.className.split(\" \").indexOf(\"check-validity\") > 0) {
|
@@ -787,7 +810,8 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
|
|
787
810
|
// And if it was the result of selecting a date, the calendar can now close.
|
788
811
|
if (inp._flatpickr &&
|
789
812
|
// Test only for changes in the date portion of a date or datetime
|
790
|
-
((giv = getInpVal()) && giv.split(' ')[0]) !== (prevVal && prevVal.split(' ')[0])
|
813
|
+
((giv = getInpVal()) && (giv1 = giv.split(' ')[0])) !== (prevVal && prevVal.split(' ')[0]) &&
|
814
|
+
giv1.indexOf(\":\") < 0 // (definitely not any part of a time thing)
|
791
815
|
)
|
792
816
|
inp._flatpickr.close();
|
793
817
|
prevVal = getInpVal();
|
data/lib/brick/version_number.rb
CHANGED
@@ -224,8 +224,8 @@ module Brick
|
|
224
224
|
# # Database schema to use when analysing existing data, such as deriving a list of polymorphic classes in the case that
|
225
225
|
# # it wasn't originally specified.
|
226
226
|
# Brick.schema_behavior = :namespaced
|
227
|
-
#{Brick.config.schema_behavior ? "Brick.schema_behavior = { multitenant: { schema_to_analyse: #{
|
228
|
-
Brick.config.schema_behavior[:multitenant]
|
227
|
+
#{Brick.config.schema_behavior.present? ? "Brick.schema_behavior = { multitenant: { schema_to_analyse: #{
|
228
|
+
Brick.config.schema_behavior[:multitenant]&.fetch(:schema_to_analyse, nil).inspect}" :
|
229
229
|
"# Brick.schema_behavior = { multitenant: { schema_to_analyse: 'engineering'"
|
230
230
|
} } }
|
231
231
|
|
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.45
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorin Thwaits
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
11
|
+
date: 2022-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|