brick 1.0.217 → 1.0.218

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: 6058423ea3fdcc6b213efcbffc1dd2d5171a08949c08338950f0dd75c35d9351
4
- data.tar.gz: 876598fc0c0bd95725340fe830af39d318bb4aa1893c6178ef2ff0547dbd1960
3
+ metadata.gz: e7506d15c361c2a616088fb916af6f5505dc19793f7267026cdd94a5e158a61c
4
+ data.tar.gz: d556d92d6063e764779c1a1e03910e151ecc75e288dd4b29d2ee44f721580f5e
5
5
  SHA512:
6
- metadata.gz: 93604235b727723b236ce5fca50f6644b53a478918acd7d20e4e60f454f62d46cf98d5c791f043db98268ad6ee77a43ed29278abf47c60ca3228347ebcd9c739
7
- data.tar.gz: 0f2a06b4b4261bf186823dca721d09c3e18a808f9449448f233738167a640d990391b309b55247c45fe8850ceab173cf2c5e5e5d62b05c0e129351bc37b61251
6
+ metadata.gz: f8092f8367ef9d86792f04f7457d8ede37ccb6502ff4396340c4b1b59a9f7ae47fbeac29a5632b44877eca27b4d0ca1296186c3749f190291da95cd68c80e29a
7
+ data.tar.gz: 706c6bd3b648abe0c44eae56c47aa17d36ee9b775d0915f517a1c7e218bfbc4997dae7b6828c4531b2fa283947234d748b6f3e615af4b1818ac0b7ee46be57ab
data/lib/brick/config.rb CHANGED
@@ -243,7 +243,6 @@ module Brick
243
243
  tables.each_with_object({}) do |v, s|
244
244
  # If it's :constellation, or anything else in a hash, we'll take its value
245
245
  # (and hopefully in this case that would be either a string or nil)
246
- # binding.pry
247
246
  dsl = ((v.last.is_a?(Symbol) && v.last) || v.last&.values&.last)
248
247
  unless (dsl ||= '').is_a?(String) || dsl.is_a?(Symbol)
249
248
  puts "Was really expecting #{v.first} / #{v.last.first&.first} / #{dsl} to be a string, " +
@@ -691,7 +691,7 @@ module ActiveRecord
691
691
  # ActiveRecord::StatementInvalid (TinyTds::Error: DBPROCESS is dead or not enabled)
692
692
  # Relevant info here: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues/402
693
693
  is_api = params['_brick_is_api']
694
- columns.each do |col|
694
+ columns[0..450].each do |col|
695
695
  next if (col.type.nil? || col.type == :binary) && is_api
696
696
 
697
697
  col_alias = " AS #{col.name}_" if (col_name = col.name) == 'class'
@@ -867,15 +867,6 @@ module ActiveRecord
867
867
  end
868
868
  v1 << id_for_tables[v.first].compact
869
869
  end
870
- # if k1.name == 'ActiveStorage::Attachment'
871
- # binding.pry
872
- # (@_brick_includes ||= {})[v1.first.first.to_s] = [v1.first[1..-1], 'blob']
873
- # # x = 5
874
- # # elsif k1.name == 'ActiveStorage::Blob'
875
- # # binding.pry
876
- # # (@_brick_includes ||= {})[v1.first.first.to_s] = v1[0..1]
877
- # # # x = 5
878
- # end
879
870
  end
880
871
  end
881
872
  join_array.each do |assoc_name|
@@ -917,12 +908,7 @@ module ActiveRecord
917
908
  through_sources.push(src_ref) unless src_ref.belongs_to?
918
909
  from_clause = +"#{_br_quoted_name(through_sources.first.table_name)} br_t0"
919
910
  # ActiveStorage will not get the correct count unless we do some extra filtering later
920
- if Object.const_defined?('ActiveStorage') && through_sources.first.klass <= ::ActiveStorage::Attachment
921
- # binding.pry
922
- tbl_nm = 'br_t0'
923
- # Need to somehow have this kind of an include in order to avoid an N+1 problem:
924
- # .include(images_attachments: [blob: { variant_records: :blob }])
925
- end
911
+ tbl_nm = 'br_t0' if Object.const_defined?('ActiveStorage') && through_sources.first.klass <= ::ActiveStorage::Attachment
926
912
  fk_col = through_sources.shift.foreign_key
927
913
 
928
914
  idx = 0
@@ -1094,7 +1080,16 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
1094
1080
  self.order_values |= final_order_by # Same as: order!(*final_order_by)
1095
1081
  end
1096
1082
  # By default just 1000 rows
1097
- row_limit = params['_brick_limit'] || params['_brick_page_size'] || 1000
1083
+ default_row_limit = if columns.length > 300
1084
+ 50
1085
+ elsif columns.length > 200
1086
+ 100
1087
+ elsif columns.length > 100
1088
+ 250
1089
+ else
1090
+ 1000
1091
+ end
1092
+ row_limit = params['_brick_limit'] || params['_brick_page_size'] || default_row_limit
1098
1093
  offset = if (page = params['_brick_page']&.to_i)
1099
1094
  page = 1 if page < 1
1100
1095
  (page - 1) * row_limit.to_i
@@ -1125,12 +1120,8 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
1125
1120
  end
1126
1121
 
1127
1122
  # ActiveStorage compatibility
1128
- if klass.name == 'ActiveStorage::Blob' && ::ActiveStorage::Blob.columns_hash.key?('service_name')
1129
- selects << 'service_name'
1130
- end
1131
- if klass.name == 'ActiveStorage::Attachment' && ::ActiveStorage::Attachment.columns_hash.key?('blob_id')
1132
- selects << 'blob_id'
1133
- end
1123
+ selects << 'service_name' if klass.name == 'ActiveStorage::Blob' && ::ActiveStorage::Blob.columns_hash.key?('service_name')
1124
+ selects << 'blob_id' if klass.name == 'ActiveStorage::Attachment' && ::ActiveStorage::Attachment.columns_hash.key?('blob_id')
1134
1125
  # Pay gem compatibility
1135
1126
  selects << 'processor' if klass.name == 'Pay::Customer' && Pay::Customer.columns_hash.key?('processor')
1136
1127
  selects << 'customer_id' if klass.name == 'Pay::Subscription' && Pay::Subscription.columns_hash.key?('customer_id')
@@ -1396,29 +1387,30 @@ end
1396
1387
  end
1397
1388
  base_module = if self < ActiveRecord::Migration || !self.name
1398
1389
  brick_root || Object
1399
- elsif split_self_name&.length&.> 1 # Classic mode
1400
- begin
1401
- base = self
1402
- unless (base_goal = requested.split('::')[0..-2].join('::')).empty?
1403
- base = base.parent while base.name != base_goal && base != Object
1404
- end
1405
- return base._brick_const_missing(*args)
1406
-
1407
- rescue NameError # %%% Avoid the error "____ cannot be autoloaded from an anonymous class or module"
1408
- return self.const_get(args.first) if self.const_defined?(args.first)
1409
-
1410
- # unless self == (prnt = (respond_to?(:parent) ? parent : module_parent))
1411
- unless self == Object
1412
- begin
1413
- return Object._brick_const_missing(*args)
1414
-
1415
- rescue NameError
1416
- return Object.const_get(args.first) if Object.const_defined?(args.first)
1417
-
1418
- end
1419
- end
1420
- end
1421
- Object
1390
+ # elsif split_self_name&.length&.> 1 # Classic mode
1391
+ # begin
1392
+ # base = self
1393
+ # unless (base_goal = requested.split('::')[0..-2].join('::')).empty?
1394
+ # base = base.parent while base.name != base_goal && base != Object
1395
+ # end
1396
+ # binding.pry
1397
+ # return base._brick_const_missing(*args)
1398
+
1399
+ # rescue NameError # %%% Avoid the error "____ cannot be autoloaded from an anonymous class or module"
1400
+ # return self.const_get(args.first) if self.const_defined?(args.first)
1401
+
1402
+ # # unless self == (prnt = (respond_to?(:parent) ? parent : module_parent))
1403
+ # unless self == Object
1404
+ # begin
1405
+ # return Object._brick_const_missing(*args)
1406
+
1407
+ # rescue NameError
1408
+ # return Object.const_get(args.first) if Object.const_defined?(args.first)
1409
+
1410
+ # end
1411
+ # end
1412
+ # end
1413
+ # Object
1422
1414
  else
1423
1415
  sti_base = (::Brick.config.sti_namespace_prefixes&.fetch("::#{name}::#{requested}", nil) ||
1424
1416
  ::Brick.config.sti_namespace_prefixes&.fetch("::#{name}::", nil))&.constantize
@@ -1685,7 +1677,10 @@ class Object
1685
1677
  schema_name = ::Brick.apartment_default_tenant
1686
1678
  end
1687
1679
  # Maybe, just maybe there's a database table that will satisfy this need
1688
- matching = ::Brick.table_name_lookup&.fetch(class_name, nil)
1680
+ matching = ::Brick.table_name_lookup&.fetch(
1681
+ base_module == Object ? class_name : "#{base_name}::#{class_name}",
1682
+ nil
1683
+ )
1689
1684
  if (matching ||= [table_name, singular_table_name, plural_class_name, model_name, table_name.titleize].find { |m| relations.key?(schema_name ? "#{schema_name}.#{m}" : m) })
1690
1685
  build_model_worker(schema_name, inheritable_name, model_name, singular_table_name, table_name, relations, matching, is_generator)
1691
1686
  end
@@ -2936,6 +2931,10 @@ module Brick
2936
2931
  end
2937
2932
  hms = (relation = relations.fetch(primary_table, nil))&.fetch(:fks) { relation[:fks] = {} } unless is_class
2938
2933
 
2934
+ unless fk[4]
2935
+ puts "WARNING: Foreign key \"#{fk[5]}\" for \"#{"#{fk[0]}." if fk[0]}#{fk[1]}.#{fk[2]}\" does not reference a valid primary key or column(s) configured with a unique constraint."
2936
+ return
2937
+ end
2939
2938
  unless (cnstr_name = fk[5])
2940
2939
  # For any appended references (those that come from config), arrive upon a definitely unique constraint name
2941
2940
  pri_tbl = is_class ? fk[4][:class].underscore : pri_tbl
@@ -582,7 +582,7 @@ window.addEventListener(\"popstate\", linkSchemas);
582
582
  alias :_brick_lookup_context :lookup_context
583
583
  def lookup_context(*args)
584
584
  ret = _brick_lookup_context(*args)
585
- @_lookup_context.instance_variable_set(:@_brick_req_params, params) if self.class < AbstractController::Base && params
585
+ @_lookup_context.instance_variable_set(:@_brick_req_params, params) if self.class < AbstractController::Base && request && params.present?
586
586
  ret
587
587
  end
588
588
  end
@@ -93,7 +93,6 @@ module Brick::Rails::FormTags
93
93
  # TinyTds::Error: Adaptive Server connection timed out
94
94
  # (After restarting the server it worked fine again.)
95
95
  row_count = 0
96
- # binding.pry
97
96
  # if @_brick_join_array&.include?()
98
97
  enumerator = relation.each # Runs the SQL query
99
98
  # Add proxied info for @_brick_includes
@@ -118,7 +117,6 @@ module Brick::Rails::FormTags
118
117
  (classes ||= []) << 'right' if val.is_a?(Numeric) && !bt
119
118
  out << " class=\"#{classes.join(' ')}\"" if classes&.present?
120
119
  out << '>'
121
- # binding.pry if col_name == 'event_image_attachment' && obj.id == 6
122
120
  if bt
123
121
  if bt[2] && obj.respond_to?(poly_id_col = "#{bt.first}_id") # Polymorphic?
124
122
  if (poly_id = obj.send(poly_id_col))
@@ -139,9 +139,10 @@ erDiagram
139
139
  @_brick_bt_descrip&.each do |bt|
140
140
  bt_class = bt[1].first.first
141
141
  callbacks[bt_name = bt_class.name.split('::').last] = bt_class
142
- is_has_one = #{model.name}.reflect_on_association(bt.first)&.inverse_of&.macro == :has_one ||
142
+ # Used to have: &.inverse_of before &.macro
143
+ is_has_one = #{model.name}.reflect_on_association(bt.first)&.macro == :has_one ||
143
144
  ::Brick.config.has_ones&.fetch('#{model.name}', nil)&.key?(bt.first.to_s)
144
- %> <%= \"#{model_short_name} #\{is_has_one ? '||' : '}o'}--|| #\{bt_name} : \\\"#\{
145
+ %> <%= \"#{model_short_name} #\{is_has_one ? '||--o|' : '}o--||'} #\{bt_name} : \\\"#\{
145
146
  bt_underscored = bt[1].first.first.name.underscore.singularize
146
147
  bt.first unless bt.first.to_s == bt_underscored.split('/').last # Was: bt_underscored.tr('/', '_')
147
148
  }\\\"\".html_safe %>
@@ -417,7 +417,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
417
417
  puts "WARNING: #{message_start} already exists.\n Will set up to auto-create model #{v[:class_name]} for table #{k}."
418
418
  end
419
419
  # Track anything that's out-of-the-ordinary
420
- table_name_lookup[v[:class_name]] = k unless v[:class_name].underscore.pluralize == k
420
+ table_name_lookup[v[:class_name]] = k.split('.').last unless v[:class_name].underscore.pluralize == k
421
421
  end
422
422
  ::Brick.load_additional_references if ::Brick.initializer_loaded
423
423
 
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 217
8
+ TINY = 218
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
@@ -189,6 +189,7 @@ module Brick
189
189
  has_uppers = name =~ /[A-Z]+/
190
190
  has_lowers = name =~ /[a-z]+/
191
191
  name.downcase! if has_uppers && action == :downcase
192
+ name = "Z#{name}" if name.start_with?('_') # Entity Framework creates a table named __EFMigrationsHistory
192
193
  if name.include?(' ')
193
194
  # All uppers or all lowers?
194
195
  if !has_uppers || !has_lowers
@@ -197,6 +198,9 @@ module Brick
197
198
  name.tr(' ', '')
198
199
  end
199
200
  else
201
+ # .NET has a background job processor called "Hangfire" which creates several tables,
202
+ # two of which get named the same as core Ruby classes -- "Set" and "Hash".
203
+ name = "#{name}x" if ['Hash', 'Set', 'hash', 'set'].include?(name)
200
204
  action == :underscore ? name.underscore : name
201
205
  end
202
206
  end
@@ -363,8 +363,8 @@ module Brick
363
363
  if (idx_name = ActiveRecord::Base.connection.index_name(tbl, {column: col})).length > 63
364
364
  # Try to find a shorter name that hasn't been used yet
365
365
  unless indexes.key?(shorter = idx_name[0..62]) ||
366
- indexes.key?(shorter = idx_name.tr('_', '')[0..62]) ||
367
- indexes.key?(shorter = idx_name.tr('aeio', '')[0..62])
366
+ indexes.key?(shorter = idx_name.tr('_', '')[0..62]) ||
367
+ indexes.key?(shorter = idx_name.tr('aeio', '')[0..62])
368
368
  puts "Unable to easily find unique name for index #{idx_name} that is shorter than 64 characters,"
369
369
  puts "so have resorted to this GUID-based identifier: #{shorter = "#{tbl[0..25]}_#{::SecureRandom.uuid}"}."
370
370
  end
@@ -379,7 +379,12 @@ module Brick
379
379
  rescue NameError => e
380
380
  primary_key = ::Brick.ar_base.primary_key
381
381
  end
382
- fk_stuff = ", foreign_key: { to_table: #{to_table}#{", primary_key: :#{primary_key}" if primary_key != ::Brick.ar_base.primary_key} }"
382
+ need_pk_specifics = (primary_key != ::Brick.ar_base.primary_key)
383
+ fk_stuff = if need_pk_specifics || to_table != ":#{fk[:assoc_name].pluralize}"
384
+ ", foreign_key: { to_table: #{to_table}#{", primary_key: :#{primary_key}" if need_pk_specifics} }"
385
+ else
386
+ ", foreign_key: true"
387
+ end
383
388
  mig << " t.references :#{fk[:assoc_name]}#{suffix}#{fk_stuff}\n"
384
389
  end
385
390
  else
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.217
4
+ version: 1.0.218
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-15 00:00:00.000000000 Z
11
+ date: 2024-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -126,16 +126,16 @@ dependencies:
126
126
  name: rspec-rails
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '4.0'
131
+ version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: '4.0'
138
+ version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -164,20 +164,6 @@ 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'
181
167
  - !ruby/object:Gem::Dependency
182
168
  name: pg
183
169
  requirement: !ruby/object:Gem::Requirement
@@ -271,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
271
257
  - !ruby/object:Gem::Version
272
258
  version: 1.3.6
273
259
  requirements: []
274
- rubygems_version: 3.2.33
260
+ rubygems_version: 3.3.26
275
261
  signing_key:
276
262
  specification_version: 4
277
263
  summary: Create a Rails app from data alone