brick 1.0.181 → 1.0.183
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 +21 -12
- data/lib/brick/frameworks/rails/form_tags.rb +2 -2
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +16 -13
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78c32d3b30786e5d03ea9cbc0decf042a808270fb7dc43809da36604d3fa8586
|
4
|
+
data.tar.gz: 9735242b6967624178bc3ed2d65368f3530fe172a27e1a7554e505d4a3ba9854
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fed1dc602b5fa4420670c7cfb923870b8fefa6ae14d61ce8a72597bc29054130eb7c871de9fcfdc06af3a7fd9b7588f4ac2267b846ba92f3c49c0b233d8a640
|
7
|
+
data.tar.gz: c613f387851e56aaa32256cd2d8170293323df3d8f86de200bf1c350b025b516df386ce608c4bef6c8d5905d377a354cf72dc949eda617b2188ed37c441ebbc9
|
data/lib/brick/extensions.rb
CHANGED
@@ -1545,8 +1545,7 @@ class Object
|
|
1545
1545
|
is_sti = true
|
1546
1546
|
else
|
1547
1547
|
# Class for auto-generated models to inherit from
|
1548
|
-
base_model = (::Brick.config.models_inherit_from ||= (
|
1549
|
-
begin
|
1548
|
+
base_model = (::Brick.config.models_inherit_from ||= (begin
|
1550
1549
|
::ApplicationRecord
|
1551
1550
|
rescue StandardError => ex
|
1552
1551
|
::ActiveRecord::Base
|
@@ -1610,9 +1609,14 @@ class Object
|
|
1610
1609
|
if has_pk
|
1611
1610
|
code << " # Primary key: #{_brick_primary_key.join(', ')}\n" unless _brick_primary_key == ['id']
|
1612
1611
|
elsif our_pks&.present?
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1612
|
+
pk_mutator = if respond_to?(:'primary_keys=')
|
1613
|
+
'primary_keys=' # Using the composite_primary_keys gem
|
1614
|
+
elsif ActiveRecord.version >= Gem::Version.new('7.1')
|
1615
|
+
'primary_key=' # Rails 7.1+?
|
1616
|
+
end
|
1617
|
+
if our_pks.length > 1 && pk_mutator
|
1618
|
+
new_model_class.send(pk_mutator, our_pks)
|
1619
|
+
code << " self.#{pk_mutator[0..-2]} = #{our_pks.map(&:to_sym).inspect}\n"
|
1616
1620
|
else
|
1617
1621
|
new_model_class.primary_key = (pk_sym = our_pks.first.to_sym)
|
1618
1622
|
code << " self.primary_key = #{pk_sym.inspect}\n"
|
@@ -1790,14 +1794,19 @@ class Object
|
|
1790
1794
|
singular_table_parts.shift
|
1791
1795
|
end
|
1792
1796
|
options[:class_name] = "::#{assoc[:primary_class]&.name || singular_table_parts.map(&:camelize).join('::')}" if need_class_name
|
1793
|
-
# Work around a bug in CPK where self-referencing belongs_to associations double up their foreign keys
|
1794
1797
|
if need_fk # Funky foreign key?
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1798
|
+
options_fk_key = :foreign_key
|
1799
|
+
if assoc[:fk].is_a?(Array)
|
1800
|
+
# #uniq works around a bug in CPK where self-referencing belongs_to associations double up their foreign keys
|
1801
|
+
if (assoc_fk = assoc[:fk].uniq).length > 1
|
1802
|
+
options_fk_key = :query_constraints if ActiveRecord.version >= ::Gem::Version.new('7.1')
|
1803
|
+
options[options_fk_key] = assoc_fk
|
1804
|
+
else
|
1805
|
+
options[options_fk_key] = assoc_fk.first
|
1806
|
+
end
|
1807
|
+
else
|
1808
|
+
options[options_fk_key] = assoc[:fk].to_sym
|
1809
|
+
end
|
1801
1810
|
end
|
1802
1811
|
if inverse_assoc_name && (need_class_name || need_fk || need_inverse_of) &&
|
1803
1812
|
(klass = options[:class_name]&.constantize) && (ian = inverse_assoc_name.tr('.', '_').to_sym) &&
|
@@ -158,7 +158,7 @@ module Brick::Rails::FormTags
|
|
158
158
|
pk.map { |pk_part| obj.send(pk_part.to_sym) }), { class: 'big-arrow' })}</td>\n" if pk.present?
|
159
159
|
sequence.each_with_index do |col_name, idx|
|
160
160
|
val = obj.attributes[col_name]
|
161
|
-
bt = bts[col_name]
|
161
|
+
bt = bts[col_name] || composite_bt_names[col_name]
|
162
162
|
out << '<td'
|
163
163
|
(classes ||= []) << 'col-sticky' if idx < nfc
|
164
164
|
(classes ||= []) << 'dimmed' unless cols.key?(col_name) || (cust_col = cust_cols[col_name]) ||
|
@@ -166,7 +166,7 @@ module Brick::Rails::FormTags
|
|
166
166
|
(classes ||= []) << 'right' if val.is_a?(Numeric) && !bt
|
167
167
|
out << " class=\"#{classes.join(' ')}\"" if classes&.present?
|
168
168
|
out << '>'
|
169
|
-
if
|
169
|
+
if bt
|
170
170
|
if bt[2] && obj.respond_to?(poly_id_col = "#{bt.first}_id") # Polymorphic?
|
171
171
|
if (poly_id = obj.send(poly_id_col))
|
172
172
|
bt_class = obj.send(klass.brick_foreign_type(bt.first))
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -203,23 +203,25 @@ module Brick
|
|
203
203
|
end
|
204
204
|
|
205
205
|
model_cols = model.columns_hash
|
206
|
-
pk_type = if (mpk = model.primary_key).is_a?(Array)
|
207
|
-
# Composite keys should really use: model.primary_key.map { |pk_part| model_cols[pk_part].type }
|
208
|
-
model_cols[mpk.first].type
|
209
|
-
else
|
210
|
-
mpk && model_cols[mpk].type
|
211
|
-
end
|
212
206
|
bts, hms = model.reflect_on_all_associations.each_with_object([{}, {}]) do |a, s|
|
213
|
-
# %%% The time will come when we will support type checking of composite foreign keys!
|
214
|
-
# binding.pry if a.foreign_key.is_a?(Array)
|
215
207
|
if a.belongs_to? && !a.polymorphic? && ::Brick.config.polymorphics.fetch(full_assoc_name = "#{model.table_name}.#{a.name}", nil)
|
216
208
|
puts "Based on inclusion in ::Brick.polymorphics, marking association #{full_assoc_name} as being polymorphic."
|
217
209
|
a.options[:polymorphic] = true
|
218
210
|
end
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
211
|
+
if !a.polymorphic? && (a.belongs_to? || (through = a.options[:through])) &&
|
212
|
+
!(a.klass && ::Brick.config.exclude_tables.exclude?(a.klass.table_name) &&
|
213
|
+
(!a.belongs_to? ||
|
214
|
+
((fk_type = a.foreign_key.is_a?(Array) ? a.foreign_key.map { |fk_part| model_cols[fk_part.to_s].type } : model_cols[a.foreign_key.to_s].type) &&
|
215
|
+
(primary_cols = a.klass.columns_hash) &&
|
216
|
+
(pk_type = a.klass.primary_key.is_a?(Array) ? a.klass.primary_key.map { |pk_part| primary_cols[pk_part.to_s].type } : primary_cols[a.klass.primary_key].type) &&
|
217
|
+
(same_type = (pk_type == fk_type))
|
218
|
+
)
|
219
|
+
)
|
220
|
+
)
|
221
|
+
# unless a.polymorphic? || (!a.belongs_to? && (through = a.options[:through])) ||
|
222
|
+
# (a.klass && ::Brick.config.exclude_tables.exclude?(a.klass.table_name) &&
|
223
|
+
# (!a.belongs_to? || (same_type = (fk_type = model_cols[a.foreign_key.to_s]&.type) == pk_type))
|
224
|
+
# )
|
223
225
|
if same_type == false # We really do want to test specifically for false here, and not nil!
|
224
226
|
puts "WARNING:
|
225
227
|
Foreign key column #{a.klass.table_name}.#{a.foreign_key} is #{fk_type}, but the primary key it relates to, #{a.active_record.table_name}.#{a.active_record.primary_key}, is #{pk_type}.
|
@@ -280,7 +282,8 @@ module Brick
|
|
280
282
|
next
|
281
283
|
end
|
282
284
|
else
|
283
|
-
|
285
|
+
this_fks = (this_fk = a.foreign_key).is_a?(Array) ? this_fk.uniq : [this_fk.to_s]
|
286
|
+
if !a.options.key?(:as) && (this_fks - a.klass.column_names).length.positive?
|
284
287
|
options = ", #{a.options.map { |k, v| "#{k.inspect} => #{v.inspect}" }.join(', ')}" if a.options.present?
|
285
288
|
puts "WARNING: Model #{model.name} has this association:
|
286
289
|
has_many :#{a.name}#{options}
|
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.183
|
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-10-
|
11
|
+
date: 2023-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: 1.42.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rswag-ui
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: mysql2
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|