brick 1.0.46 → 1.0.47
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 +30 -16
- data/lib/brick/frameworks/rails/engine.rb +19 -6
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +6 -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: 4180c0164d7f086112339696df9d8fef2aeebcd32d9b81faf22d76ddc11815bc
|
4
|
+
data.tar.gz: 823673bcbecc342f5df15e196ee65ad6f6ac0b75415514079c055af06d0ac7f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d17b1abd64051066b71839095be1e672b897ad707a2d10f4ca4429131c894ee178711c873cef59957111704437b86b6322b8909ab5cc41cc955547146377dd8
|
7
|
+
data.tar.gz: e210becff69096e73b9b7fa09bb4e1be6c36cd2982305b2c803c9c00e9d2b5b085857ea6edacc62498557cde928e2afbbb42ebbd137180385ec3a8a0c5efdf85
|
data/lib/brick/extensions.rb
CHANGED
@@ -596,7 +596,7 @@ Module.class_exec do
|
|
596
596
|
# See if a file is there in the same way that ActiveSupport::Dependencies#load_missing_constant
|
597
597
|
# checks for it in ~/.rvm/gems/ruby-2.7.5/gems/activesupport-5.2.6.2/lib/active_support/dependencies.rb
|
598
598
|
|
599
|
-
if (base_model = ::Brick.config.sti_namespace_prefixes&.fetch("::#{name}::", nil)&.constantize) || # Are we part of an auto-STI namespace? ...
|
599
|
+
if (base_model = ::Brick.config.sti_namespace_prefixes&.fetch("::#{self.name}::", nil)&.constantize) || # Are we part of an auto-STI namespace? ...
|
600
600
|
self != Object # ... or otherwise already in some namespace?
|
601
601
|
schema_name = [(singular_schema_name = name.underscore),
|
602
602
|
(schema_name = singular_schema_name.pluralize),
|
@@ -773,33 +773,47 @@ class Object
|
|
773
773
|
end # class definition
|
774
774
|
# Having this separate -- will this now work out better?
|
775
775
|
built_model.class_exec do
|
776
|
-
hmts&.each do |hmt_fk,
|
776
|
+
hmts&.each do |hmt_fk, hms|
|
777
777
|
hmt_fk = hmt_fk.tr('.', '_')
|
778
|
-
|
779
|
-
# %%%
|
780
|
-
through = ::Brick.config.schema_behavior[:multitenant] ?
|
781
|
-
|
782
|
-
|
783
|
-
|
778
|
+
hms.each do |hm|
|
779
|
+
# %%% Need to confirm that HMTs work when they are built from has_manys with custom names
|
780
|
+
through = ::Brick.config.schema_behavior[:multitenant] ? hm.first[:assoc_name] : hm.first[:inverse_table].tr('.', '_').pluralize
|
781
|
+
options = {}
|
782
|
+
hmt_name = if hms.length > 1
|
783
|
+
if hms[0].first[:inverse][:assoc_name] == hms[1].first[:inverse][:assoc_name] # Same BT names pointing back to us? (Most common scenario)
|
784
|
+
"#{hmt_fk}_through_#{hm.first[:assoc_name]}"
|
784
785
|
else # Use BT names to provide uniqueness
|
785
|
-
|
786
|
-
|
786
|
+
if self.name.underscore.singularize == hm.first[:alternate_name]
|
787
|
+
# Has previously been:
|
788
|
+
# # If it folds back on itself then look at the other side
|
789
|
+
# # (At this point just infer the source be the inverse of the first has_many that
|
790
|
+
# # we find that is not ourselves. If there are more than two then uh oh, can't
|
791
|
+
# # yet handle that rare circumstance!)
|
792
|
+
# other = hms.find { |hm1| hm1 != hm } # .first[:fk]
|
793
|
+
# options[:source] = other.first[:inverse][:assoc_name].to_sym
|
794
|
+
# And also has been:
|
795
|
+
# hm.first[:inverse][:assoc_name].to_sym
|
796
|
+
options[:source] = hm.last.to_sym
|
797
|
+
else
|
798
|
+
through = hm.first[:alternate_name].pluralize
|
799
|
+
end
|
800
|
+
singular_assoc_name = hm.first[:inverse][:assoc_name].singularize
|
787
801
|
"#{singular_assoc_name}_#{hmt_fk}"
|
788
802
|
end
|
789
803
|
else
|
790
804
|
hmt_fk
|
791
805
|
end
|
792
|
-
options =
|
806
|
+
options[:through] = through.to_sym
|
793
807
|
if relation[:fks].any? { |k, v| v[:assoc_name] == hmt_name }
|
794
|
-
hmt_name = "#{hmt_name.singularize}_#{
|
808
|
+
hmt_name = "#{hmt_name.singularize}_#{hm.first[:assoc_name]}"
|
795
809
|
# Was:
|
796
|
-
# options[:class_name] =
|
797
|
-
# options[:foreign_key] =
|
798
|
-
far_assoc = relations[
|
810
|
+
# options[:class_name] = hm.first[:inverse_table].singularize.camelize
|
811
|
+
# options[:foreign_key] = hm.first[:fk].to_sym
|
812
|
+
far_assoc = relations[hm.first[:inverse_table]][:fks].find { |_k, v| v[:assoc_name] == hm.last }
|
799
813
|
options[:class_name] = far_assoc.last[:inverse_table].singularize.camelize
|
800
814
|
options[:foreign_key] = far_assoc.last[:fk].to_sym
|
801
815
|
end
|
802
|
-
options[:source]
|
816
|
+
options[:source] ||= hm.last.to_sym unless hmt_name.singularize == hm.last
|
803
817
|
code << " has_many :#{hmt_name}#{options.map { |opt| ", #{opt.first}: #{opt.last.inspect}" }.join}\n"
|
804
818
|
self.send(:has_many, hmt_name.to_sym, **options)
|
805
819
|
end
|
@@ -105,13 +105,26 @@ module Brick
|
|
105
105
|
hms_columns = [] # Used for 'index'
|
106
106
|
skip_klass_hms = ::Brick.config.skip_index_hms[model_name] || {}
|
107
107
|
hms_headers = hms.each_with_object([]) do |hm, s|
|
108
|
-
hm_stuff = [(hm_assoc = hm.last),
|
108
|
+
hm_stuff = [(hm_assoc = hm.last),
|
109
|
+
"H#{hm_assoc.macro == :has_one ? 'O' : 'M'}#{'T' if hm_assoc.options[:through]}",
|
110
|
+
(assoc_name = hm.first)]
|
109
111
|
hm_fk_name = if hm_assoc.options[:through]
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
associative = associatives[hm.first]
|
113
|
+
tbl_nm = if hm_assoc.options[:source]
|
114
|
+
associative.klass.reflect_on_association(hm_assoc.options[:source]).inverse_of&.name
|
115
|
+
else
|
116
|
+
associative.name
|
117
|
+
end
|
118
|
+
# If there is no inverse available for the source belongs_to association, make one based on the class name
|
119
|
+
unless tbl_nm
|
120
|
+
tbl_nm = associative.class_name.underscore
|
121
|
+
tbl_nm.slice!(0) if tbl_nm[0] == ('/')
|
122
|
+
tbl_nm = tbl_nm.tr('/', '_').pluralize
|
123
|
+
end
|
124
|
+
"'#{tbl_nm}.#{associative.foreign_key}'"
|
125
|
+
else
|
126
|
+
hm_assoc.foreign_key
|
127
|
+
end
|
115
128
|
case args.first
|
116
129
|
when 'index'
|
117
130
|
hms_columns << if hm_assoc.macro == :has_many
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -168,8 +168,12 @@ module Brick
|
|
168
168
|
skip_hms = {}
|
169
169
|
associatives = hms.each_with_object({}) do |hmt, s|
|
170
170
|
if (through = hmt.last.options[:through])
|
171
|
-
skip_hms[through] = nil
|
172
|
-
|
171
|
+
skip_hms[through] = nil # if hms[through]
|
172
|
+
# binding.pry if !hms[through]
|
173
|
+
# End up with a hash of HMT names pointing to join-table associations
|
174
|
+
# Last part was: hmt.last.name
|
175
|
+
# Changed up because looking for: hms[:issue_issue_duplicates]
|
176
|
+
s[hmt.first] = hms[through] # || hms["#{(opt = hmt.last.options)[:through].to_s.singularize}_#{opt[:source].to_s.pluralize}".to_sym]
|
173
177
|
elsif hmt.last.inverse_of.nil?
|
174
178
|
puts "SKIPPING #{hmt.last.name.inspect}"
|
175
179
|
# %%% If we don't do this then below associative.name will find that associative is nil
|
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.47
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|