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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 322ed139c5ec7c48572ab2ea87830998fe742c32ac56e91d2eed97084f7d8c42
4
- data.tar.gz: 836c21610811fb2322bdfd572d2b1ccce0a23464bf54512ae160149a6bfdb972
3
+ metadata.gz: 78c32d3b30786e5d03ea9cbc0decf042a808270fb7dc43809da36604d3fa8586
4
+ data.tar.gz: 9735242b6967624178bc3ed2d65368f3530fe172a27e1a7554e505d4a3ba9854
5
5
  SHA512:
6
- metadata.gz: 034b252fc08bc09216a33d8cd34a97c4afa81a86943d319e0bccd26a387060d69a3d1e0b80de2ba29e9f57c06e7eff3b41cbdfa92354f8a754e350b0ab8daacf
7
- data.tar.gz: 0ba1422cb56af76c4e0eb89de5fd940a90dcfb93fd90016852cb9631d71542825dea0187fd44ac66fa65a79905583b9dec92b3615b67db1f16d4ad5e5357f1ac
6
+ metadata.gz: 7fed1dc602b5fa4420670c7cfb923870b8fefa6ae14d61ce8a72597bc29054130eb7c871de9fcfdc06af3a7fd9b7588f4ac2267b846ba92f3c49c0b233d8a640
7
+ data.tar.gz: c613f387851e56aaa32256cd2d8170293323df3d8f86de200bf1c350b025b516df386ce608c4bef6c8d5905d377a354cf72dc949eda617b2188ed37c441ebbc9
@@ -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 ||= (app.config.brick.fetch(:models_inherit_from, nil) ||
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
- if our_pks.length > 1 && respond_to?(:'primary_keys=') # Using the composite_primary_keys gem?
1614
- new_model_class.primary_keys = our_pks
1615
- code << " self.primary_keys = #{our_pks.map(&:to_sym).inspect}\n"
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
- options[:foreign_key] = if assoc[:fk].is_a?(Array)
1796
- assoc_fk = assoc[:fk].uniq
1797
- assoc_fk.length < 2 ? assoc_fk.first : assoc_fk
1798
- else
1799
- assoc[:fk].to_sym
1800
- end
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 (bt || composite_bt_names[col_name])
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))
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 181
8
+ TINY = 183
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
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
- unless a.polymorphic? || (!a.belongs_to? && (through = a.options[:through])) ||
220
- (a.klass && ::Brick.config.exclude_tables.exclude?(a.klass.table_name) &&
221
- (!a.belongs_to? || (same_type = (fk_type = model_cols[a.foreign_key]&.type) == pk_type))
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
- if !a.options.key?(:as) && a.klass.column_names.exclude?(a.foreign_key.to_s)
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.181
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-09 00:00:00.000000000 Z
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