brick 1.0.43 → 1.0.44
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 +25 -13
- data/lib/brick/frameworks/rails/engine.rb +13 -8
- data/lib/brick/version_number.rb +1 -1
- data/lib/generators/brick/install_generator.rb +1 -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: 0d43e8d88203f6496d0e86f57a3de2638f254a74da070d6a0f0ae107bf596a87
|
4
|
+
data.tar.gz: d5ce2e3814f36fa758762e3c4774032c70ce18a101cdd1e30622dd86c757ab1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36b8bf590c1d980655b8c465e52659fdbcdf3e13b7050e46dcb41c2b3fba44ebc9ff14db823afddbb49b3e6b736a33fa1ef794ed6062aba4e35ade3cd95c5bbd
|
7
|
+
data.tar.gz: d1bd0954d0400068aaf8f7c83cc599f283fbe9c75e347fd4193d1fa3973c0d2bd3198f3265990cd3d24f406cd3b55f3174518bd6a991801c75a06d1c749cc157
|
data/lib/brick/extensions.rb
CHANGED
@@ -354,6 +354,7 @@ module ActiveRecord
|
|
354
354
|
next if bt[2] # Polymorphic?
|
355
355
|
|
356
356
|
# join_array will receive this relation name when calling #brick_parse_dsl
|
357
|
+
# binding.pry if bt.length > 2
|
357
358
|
bt_descrip[bt.first] = if bt[1].is_a?(Array)
|
358
359
|
bt[1].each_with_object({}) { |bt_class, s| s[bt_class] = bt_class.brick_parse_dsl(join_array, bt.first, translations, true) }
|
359
360
|
else
|
@@ -364,7 +365,12 @@ module ActiveRecord
|
|
364
365
|
hms.each do |k, hm|
|
365
366
|
next if skip_klass_hms.key?(k)
|
366
367
|
|
367
|
-
|
368
|
+
if hm.macro == :has_one
|
369
|
+
# For our purposes a :has_one is similar enough to a :belongs_to that we can just join forces
|
370
|
+
bt_descrip[k] = { hm.klass => hm.klass.brick_parse_dsl(join_array, k, translations) }
|
371
|
+
else # Standard :has_many
|
372
|
+
hm_counts[k] = hm
|
373
|
+
end
|
368
374
|
end
|
369
375
|
end
|
370
376
|
|
@@ -650,10 +656,11 @@ class Object
|
|
650
656
|
private
|
651
657
|
|
652
658
|
def build_model(schema_name, inheritable_name, model_name, singular_table_name, table_name, relations, matching)
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
659
|
+
if ::Brick.config.schema_behavior[:multitenant] && Object.const_defined?('Apartment') &&
|
660
|
+
schema_name == Apartment.default_schema
|
661
|
+
relation = relations["#{schema_name}.#{matching}"]
|
662
|
+
end
|
663
|
+
full_name = if relation || schema_name.blank?
|
657
664
|
inheritable_name || model_name
|
658
665
|
else # Prefix the schema to the table name + prefix the schema namespace to the class name
|
659
666
|
schema_module = if schema_name.instance_of?(Module) # from an auto-STI namespace?
|
@@ -749,10 +756,10 @@ class Object
|
|
749
756
|
if assoc[:is_bt]
|
750
757
|
invs = invs.first # Just do the first one of what would be multiple identical polymorphic belongs_to
|
751
758
|
else
|
752
|
-
invs.each { |inv| build_bt_or_hm(
|
759
|
+
invs.each { |inv| build_bt_or_hm(full_name, relations, relation, hmts, assoc, inverse_assoc_name, inv, code) }
|
753
760
|
end
|
754
761
|
end
|
755
|
-
build_bt_or_hm(
|
762
|
+
build_bt_or_hm(full_name, relations, relation, hmts, assoc, inverse_assoc_name, invs, code) unless invs.is_a?(Array)
|
756
763
|
hmts
|
757
764
|
end
|
758
765
|
# # Not NULLables
|
@@ -804,7 +811,7 @@ class Object
|
|
804
811
|
[built_model, code]
|
805
812
|
end
|
806
813
|
|
807
|
-
def build_bt_or_hm(
|
814
|
+
def build_bt_or_hm(full_name, relations, relation, hmts, assoc, inverse_assoc_name, inverse_table, code)
|
808
815
|
singular_table_name = inverse_table&.singularize
|
809
816
|
options = {}
|
810
817
|
macro = if assoc[:is_bt]
|
@@ -826,8 +833,14 @@ class Object
|
|
826
833
|
end
|
827
834
|
if (inverse = assoc[:inverse])
|
828
835
|
inverse_assoc_name, _x = _brick_get_hm_assoc_name(relations[inverse_table], inverse)
|
829
|
-
|
830
|
-
if
|
836
|
+
# If it's multitenant with something like: public.____ ...
|
837
|
+
if (it_parts = inverse_table.split('.')).length > 1 &&
|
838
|
+
::Brick.config.schema_behavior[:multitenant] && Object.const_defined?('Apartment') &&
|
839
|
+
it_parts.first == Apartment.default_schema
|
840
|
+
it_parts.shift # ... then ditch the generic schema name
|
841
|
+
end
|
842
|
+
has_ones = ::Brick.config.has_ones&.fetch(it_parts.join('/').singularize.camelize, nil)
|
843
|
+
if has_ones&.key?(singular_inv_assoc_name = ActiveSupport::Inflector.singularize(inverse_assoc_name.tr('.', '_')))
|
831
844
|
inverse_assoc_name = if has_ones[singular_inv_assoc_name]
|
832
845
|
need_inverse_of = true
|
833
846
|
has_ones[singular_inv_assoc_name]
|
@@ -838,7 +851,6 @@ class Object
|
|
838
851
|
end
|
839
852
|
:belongs_to
|
840
853
|
else
|
841
|
-
# need_class_name = ActiveSupport::Inflector.singularize(assoc_name) == ActiveSupport::Inflector.singularize(table_name.underscore)
|
842
854
|
# Are there multiple foreign keys out to the same table?
|
843
855
|
assoc_name, need_class_name = _brick_get_hm_assoc_name(relation, assoc)
|
844
856
|
if assoc.key?(:polymorphic)
|
@@ -846,8 +858,8 @@ class Object
|
|
846
858
|
else
|
847
859
|
need_fk = "#{ActiveSupport::Inflector.singularize(assoc[:inverse][:inverse_table].split('.').last)}_id" != assoc[:fk]
|
848
860
|
end
|
849
|
-
|
850
|
-
if
|
861
|
+
has_ones = ::Brick.config.has_ones&.fetch(full_name, nil)
|
862
|
+
if has_ones&.key?(singular_assoc_name = ActiveSupport::Inflector.singularize(assoc_name.tr('.', '_')))
|
851
863
|
assoc_name = if (custom_assoc_name = has_ones[singular_assoc_name])
|
852
864
|
need_class_name = custom_assoc_name != singular_assoc_name
|
853
865
|
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
|
@@ -574,11 +578,11 @@ if (headerTop) {
|
|
574
578
|
else
|
575
579
|
bt_txt = (bt_class = bt[1].first.first).brick_descrip(
|
576
580
|
# 0..62 because Postgres column names are limited to 63 characters
|
577
|
-
#{obj_name}, (descrips = @_brick_bt_descrip[bt.first][bt_class])[0..-2].map { |
|
581
|
+
#{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)
|
578
582
|
)
|
579
583
|
bt_txt ||= \"<< Orphaned ID: #\{val} >>\" if val
|
580
|
-
bt_id = #{obj_name}.send(
|
581
|
-
<%= bt_id ? link_to(bt_txt, send(\"#\{bt_class.base_class.name.underscore.tr('/', '_')\}_path\".to_sym, bt_id)) : bt_txt %>
|
584
|
+
bt_id = bt_id_col.map { |id_col| #{obj_name}.send(id_col.to_sym) } if bt_id_col&.present? %>
|
585
|
+
<%= bt_id&.first ? link_to(bt_txt, send(\"#\{bt_class.base_class.name.underscore.tr('/', '_')\}_path\".to_sym, bt_id)) : bt_txt %>
|
582
586
|
<%#= 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 %>
|
583
587
|
<% end %>
|
584
588
|
<% else %>
|
@@ -697,10 +701,6 @@ end
|
|
697
701
|
<% when :boolean %>
|
698
702
|
<%= f.check_box k.to_sym %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
|
699
703
|
<% when :integer, :decimal, :float
|
700
|
-
# What happens when keys are UUID?
|
701
|
-
# Postgres naturally uses the +uuid_generate_v4()+ function from the uuid-ossp extension
|
702
|
-
# If it's not yet enabled then: enable_extension 'uuid-ossp'
|
703
|
-
# ActiveUUID gem created a new :uuid type %>
|
704
704
|
<%= if col_type == :integer
|
705
705
|
f.text_field k.to_sym, { pattern: '\\d*', class: 'check-validity' }
|
706
706
|
else
|
@@ -709,6 +709,11 @@ end
|
|
709
709
|
<% when *dt_pickers.keys
|
710
710
|
is_includes_dates = true %>
|
711
711
|
<%= 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>
|
712
|
+
<% when :uuid %>
|
713
|
+
# Postgres naturally uses the +uuid_generate_v4()+ function from the uuid-ossp extension
|
714
|
+
# If it's not yet enabled then: enable_extension 'uuid-ossp'
|
715
|
+
# ActiveUUID gem created a new :uuid type %>
|
716
|
+
<%= val %>
|
712
717
|
<% when :binary, :primary_key %>
|
713
718
|
<% end %>
|
714
719
|
<% end %>
|
data/lib/brick/version_number.rb
CHANGED
@@ -224,7 +224,7 @@ 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: #{
|
227
|
+
#{Brick.config.schema_behavior.present? ? "Brick.schema_behavior = { multitenant: { schema_to_analyse: #{
|
228
228
|
Brick.config.schema_behavior[:multitenant]&.fetch(:schema_to_analyse, nil).inspect}" :
|
229
229
|
"# Brick.schema_behavior = { multitenant: { schema_to_analyse: 'engineering'"
|
230
230
|
} } }
|
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.44
|
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
|