brick 1.0.236 → 1.0.239

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: 8397091edab4be1edd1e61eb4be3284a8c169a3207f87e92227b84d07413d241
4
- data.tar.gz: 2ffaef636cfba92e38bf9330f04a5bd65f39eb06d62e002e5227f7261b126494
3
+ metadata.gz: 7fc4a9f9ff2721cfc065f6765eb2e9a661a8aa3339c2bf23aa367d6342b6ce1d
4
+ data.tar.gz: f2270956a65f66cbae1c4e59bbd5c2a395406099a699ed649a31d279cbdefe46
5
5
  SHA512:
6
- metadata.gz: 38d24e9e8ae60a63f6755bb5e0854880df019ce4004d3e8962c8a47cfc80bb23fcba576216e9cedf7560f37b458ce47e651ccaa206b0e92844519e2a932d7c7e
7
- data.tar.gz: 4f33bd865494dcd1855204bd5c307f8b2fc70485bd8ce5c9fd79708df638ff0f715d44755087a0c8230589dd3679d238dfdaeea8807dc14cf4a658fae21ffa7d
6
+ metadata.gz: 89d81c26f4090cf8892780701ffb594c859c94c21fa5d3a7ff2dd24bcf7246992423221d71a417d48fecc29c5475bfb64c73814ddef219cdd192a80bc3ce414d
7
+ data.tar.gz: 6ca286b5fd22ac2316860373fcab4c7650010bf723f82ce587327f7d6ce1cc5aecf976ce4b2268c4031a7e78d58fc29fc6a695f9570248c4285e35cd95f4c8ad
@@ -416,7 +416,7 @@ module ActiveRecord
416
416
  @_br_cust_cols ||= {}
417
417
  end
418
418
 
419
- def _brick_find_permits(model_or_assoc, current_permits, done_permits = [])
419
+ def _brick_find_permits(model_or_assoc, current_permits, is_for_expects = nil, done_permits = [])
420
420
  unless done_permits.include?(model_or_assoc)
421
421
  done_permits << model_or_assoc
422
422
  self.reflect_on_all_associations.select { |assoc| !assoc.belongs_to? }.each_with_object([]) do |assoc, s|
@@ -430,6 +430,7 @@ module ActiveRecord
430
430
  assoc.klass.instance_variable_get(:@friendly_id_config)
431
431
  new_attrib_text = assoc.klass._brick_find_permits(assoc, (new_permits = assoc.klass._brick_all_fields), done_permits)
432
432
  new_permits << :_destroy
433
+ new_permits = [new_permits] if is_for_expects
433
434
  current_permits << { "#{assoc.name}_attributes".to_sym => new_permits }
434
435
  s << "#{assoc.name}_attributes: #{new_attrib_text}"
435
436
  end
@@ -1437,12 +1438,13 @@ end
1437
1438
  if (self.const_defined?(args.first) && (possible = self.const_get(args.first)) &&
1438
1439
  # Reset `possible` if it's a controller request that's not a perfect match
1439
1440
  # Was: (possible = nil) but changed to #local_variable_set in order to suppress the "= should be ==" warning
1440
- (possible&.name == desired_classname || (is_controller && binding.local_variable_set(:possible, nil)))) ||
1441
+ (possible&.name == desired_classname || (is_controller && binding.local_variable_set(:possible, nil)))
1442
+ ) ||
1441
1443
 
1442
1444
  # Try to require the respective Ruby file
1443
1445
  # ((filename = ActiveSupport::Dependencies.search_for_file(desired_classname.underscore)) &&
1444
1446
  # (require_dependency(filename) || true) &&
1445
- (!anonymous? &&
1447
+ (!anonymous? && # Don't try to find classes first mentioned in .erb or .haml templates
1446
1448
  (filename = ActiveSupport::Dependencies.search_for_file(desired_classname.underscore) ||
1447
1449
  (self != Object && ActiveSupport::Dependencies.search_for_file((desired_classname = requested).underscore))
1448
1450
  ) && (require_dependency(filename) || true) &&
@@ -2026,7 +2028,8 @@ class Object
2026
2028
  else
2027
2029
  need_fk = "#{ActiveSupport::Inflector.singularize(assoc[:inverse][:inverse_table].split('.').last)}_id" != assoc[:fk]
2028
2030
  end
2029
- singular_assoc_name = ActiveSupport::Inflector.singularize(assoc_name.tr('.', '_'))
2031
+ full_assoc_name = assoc_name.tr('.', '_')
2032
+ singular_assoc_name = ActiveSupport::Inflector.singularize(full_assoc_name)
2030
2033
  has_ones = ::Brick.config.has_ones&.fetch(full_name, nil)
2031
2034
  macro = if has_ones&.key?(singular_assoc_name)
2032
2035
  assoc_name = if (custom_assoc_name = has_ones[singular_assoc_name])
@@ -2041,7 +2044,7 @@ class Object
2041
2044
  end
2042
2045
  # Auto-create an accepts_nested_attributes_for for this HM?
2043
2046
  is_anaf = (anaf = ::Brick.config.nested_attributes&.fetch(full_name, nil)) &&
2044
- (anaf.is_a?(Array) ? anaf.include?(assoc_name) : anaf == assoc_name)
2047
+ (anaf.is_a?(Array) ? anaf.include?(full_assoc_name) : anaf == full_assoc_name)
2045
2048
  macro
2046
2049
  end
2047
2050
  if (singular_table_parts = singular_table_name.split('.')).length > 1 &&
@@ -2058,7 +2061,9 @@ class Object
2058
2061
  if assoc[:fk].is_a?(Array)
2059
2062
  # #uniq works around a bug in CPK where self-referencing belongs_to associations double up their foreign keys
2060
2063
  if (assoc_fk = assoc[:fk].uniq).length > 1
2061
- options_fk_key = :query_constraints if ActiveRecord.version >= ::Gem::Version.new('7.1')
2064
+ # The :query_constraints option was only valid for Rails 7.1 and 7.2. Starting in Rails 8 you will get this:
2065
+ # Setting `query_constraints:` option on `Sales::Specialofferproduct.has_many :sales_salesorderdetails` is not allowed. To get the same behavior, use the `foreign_key` option instead.
2066
+ options_fk_key = :query_constraints if ActiveRecord.version >= ::Gem::Version.new('7.1') && ActiveRecord.version < ::Gem::Version.new('8.0a')
2062
2067
  options[options_fk_key] = assoc_fk
2063
2068
  else
2064
2069
  options[options_fk_key] = assoc_fk.first
@@ -2100,8 +2105,8 @@ class Object
2100
2105
  code << " #{macro} #{assoc_name.inspect}#{options.map { |k, v| ", #{k}: #{v.inspect}" }.join}\n"
2101
2106
  self.send(macro, assoc_name, **options)
2102
2107
  if is_anaf
2103
- code << " accepts_nested_attributes_for #{assoc_name.inspect}\n"
2104
- self.send(:accepts_nested_attributes_for, assoc_name)
2108
+ code << " accepts_nested_attributes_for #{full_assoc_name.to_sym.inspect}\n"
2109
+ self.send(:accepts_nested_attributes_for, full_assoc_name)
2105
2110
  end
2106
2111
  end
2107
2112
 
@@ -2260,7 +2265,7 @@ class Object
2260
2265
  return
2261
2266
  end
2262
2267
 
2263
- # Apartment::Tenant.switch!(params['schema'])
2268
+ Apartment::Tenant.switch!(params['_brick_schema']) if Object.const_defined?('Apartment')
2264
2269
  # result = ActiveRecord::Base.connection.query("SELECT #{cols.join(', ')} FROM #{view}")
2265
2270
  col_num = 0
2266
2271
  grouping = []
@@ -2286,7 +2291,7 @@ class Object
2286
2291
  end
2287
2292
  s << "#{col_def} AS c#{col_num}"
2288
2293
  end
2289
- sql = "SELECT #{cols.join(', ')} FROM #{first_relation.downcase}"
2294
+ sql = +"SELECT #{cols.join(', ')} FROM #{first_relation.downcase}"
2290
2295
  sql << "\nGROUP BY #{grouping.map(&:to_s).join(',')}" if is_grouped && grouping.present?
2291
2296
  result = ActiveRecord::Base.connection.query(sql)
2292
2297
  render json: { data: result } # [ver, result]
@@ -2760,7 +2765,11 @@ class Object
2760
2765
  end
2761
2766
  obj.send(:update, upd_hash)
2762
2767
  if obj.errors.any? # Surface errors to the user in a flash message
2763
- flash.now.alert = (obj.errors.errors.map { |err| "<b>#{err.attribute}</b> #{err.message}" }.join(', '))
2768
+ flash.now.alert = if obj.errors.respond_to?(:errors)
2769
+ obj.errors.errors.map { |err| "<b>#{err.attribute}</b> #{err.message}" }.join(', ')
2770
+ else
2771
+ obj.errors.messages.map { |k, v| "<b>#{k}</b> #{v}" }.join(', ')
2772
+ end
2764
2773
  end
2765
2774
  end
2766
2775
 
@@ -2809,12 +2818,26 @@ class Object
2809
2818
 
2810
2819
  if is_need_params
2811
2820
  code << " def #{params_name}\n"
2812
- permits_txt = model._brick_find_permits(model, permits = model._brick_all_fields(true))
2813
- code << " params.require(:#{model.base_class.name.underscore.tr('/', '_')
2814
- }).permit(#{permits_txt.map(&:inspect).join(', ')})\n"
2815
- code << " end\n"
2816
- self.define_method(params_name) do
2817
- params.require(model.base_class.name.underscore.tr('/', '_').to_sym).permit(permits)
2821
+ require_txt = model.base_class.name.underscore.tr('/', '_')
2822
+ is_for_expects = ::ActiveSupport.version >= ::Gem::Version.new('8.0a')
2823
+ permits_txt = model._brick_find_permits(model, permits = model._brick_all_fields(true), is_for_expects)
2824
+ if is_for_expects
2825
+ code << " params.expect(#{require_txt
2826
+ }: #{permits_txt})\n"
2827
+ code << " end\n"
2828
+ else
2829
+ code << " params.require(:#{require_txt
2830
+ }).permit(#{permits_txt.map(&:inspect).join(', ')})\n"
2831
+ code << " end\n"
2832
+ end
2833
+ if is_for_expects
2834
+ self.define_method(params_name) do
2835
+ params.expect({ model.base_class.name.underscore.tr('/', '_').to_sym => permits })
2836
+ end
2837
+ else
2838
+ self.define_method(params_name) do
2839
+ params.require(model.base_class.name.underscore.tr('/', '_').to_sym).permit(permits)
2840
+ end
2818
2841
  end
2819
2842
  private params_name
2820
2843
  # Get column names for params from relations[model.table_name][:cols].keys
Binary file
@@ -672,7 +672,7 @@ window.addEventListener(\"popstate\", linkSchemas);
672
672
  find_template_err = nil
673
673
  unless (model_name = @_brick_model&.name) ||
674
674
  (
675
- args[1].first == 'brick_gem' &&
675
+ args[1]&.first == 'brick_gem' &&
676
676
  ((is_search = ::Brick.config.add_search && args[0] == 'search' &&
677
677
  ::Brick.elasticsearch_existings&.length&.positive?
678
678
  ) ||
@@ -1012,7 +1012,7 @@ if (window.brickFontFamily) {
1012
1012
  +"<html>
1013
1013
  <head>
1014
1014
  #{css}
1015
- <title><%= (model = #{model_name}).name %><%
1015
+ <title><%= (model = ::#{model_name}).name %><%
1016
1016
  if (description = (relation = Brick.relations[model.table_name])&.fetch(:description, nil)).present?
1017
1017
  %> - <%= description
1018
1018
  %><% end
@@ -1330,11 +1330,10 @@ end
1330
1330
 
1331
1331
  when 'crosstab'
1332
1332
  if is_crosstab && ::Brick.config.license
1333
- decipher = OpenSSL::Cipher::AES256.new(:CBC).decrypt
1334
- decipher.iv = "\xB4,\r2\x19\xF5\xFE/\aR\x1A\x8A\xCFV\v\x8C"
1333
+ encrypted = File.binread("#{Gem::Specification.find_by_name('brick').gem_dir}/lib/brick/rails/crosstab.brk")
1334
+ (decipher = OpenSSL::Cipher::AES256.new(:CBC).decrypt).iv = encrypted[0..15]
1335
1335
  decipher.key = Digest::SHA256.hexdigest(::Brick.config.license).scan(/../).map { |x| x.hex }.pack('c*')
1336
- brick_path = Gem::Specification.find_by_name('brick').gem_dir
1337
- decipher.update(File.binread("#{brick_path}/lib/brick/rails/crosstab.brk"))[16..-1]
1336
+ decipher.update(encrypted[16..-1]) + decipher.final
1338
1337
  else
1339
1338
  'Crosstab Charting not yet activated -- enter a valid license key in brick.rb'
1340
1339
  end
@@ -1347,12 +1346,13 @@ end
1347
1346
  if (model = (obj = @#{obj_name})&.class || @lookup_context&.instance_variable_get(:@_brick_model))
1348
1347
  see_all_path = send(\"#\{(base_model = model.base_class)._brick_index}_path\")
1349
1348
  #{(inh_col = @_brick_model.inheritance_column).present? &&
1350
- " if obj.respond_to?(:#{inh_col}) && (model_name = @#{obj_name}.#{inh_col}) &&
1351
- !model_name.is_a?(Numeric) && model_name != base_model.name
1352
- see_all_path << \"?#{inh_col}=#\{model_name}\"
1349
+ " if obj.respond_to?(:#{inh_col}) && (model_name = @#{obj_name}.#{inh_col}) &&
1350
+ !model_name.is_a?(Numeric) && model_name != base_model.name
1351
+ see_all_path << \"?#{inh_col}=#\{model_name}\"
1352
+ end
1353
+ model_name = base_model.name if model_name.is_a?(Numeric)"}
1354
+ model_name = nil if model_name == ''
1353
1355
  end
1354
- model_name = base_model.name if model_name.is_a?(Numeric)"}
1355
- model_name = nil if model_name == ''
1356
1356
  page_title = (\"#\{model_name ||= model.name}: #\{obj&.brick_descrip || controller_name}\")
1357
1357
  %></title>
1358
1358
  </head>
data/lib/brick/rails.rb CHANGED
@@ -140,7 +140,7 @@ erDiagram
140
140
  bt_class = bt[1].first.first
141
141
  callbacks[bt_name = bt_class.name.split('::').last] = bt_class
142
142
  # Used to have: &.inverse_of before &.macro
143
- is_has_one = #{model.name}.reflect_on_association(bt.first)&.macro == :has_one ||
143
+ is_has_one = ::#{model.name}.reflect_on_association(bt.first)&.macro == :has_one ||
144
144
  ::Brick.config.has_ones&.fetch('#{model.name}', nil)&.key?(bt.first.to_s)
145
145
  %> <%= \"#{model_short_name} #\{is_has_one ? '||--o|' : '}o--||'} #\{bt_name} : \\\"#\{
146
146
  bt_underscored = bt[1].first.first.name.underscore.singularize
@@ -151,7 +151,7 @@ erDiagram
151
151
  last_hm = nil
152
152
  @_brick_hm_counts&.each do |hm|
153
153
  # Skip showing self-referencing HM links since they would have already been drawn while evaluating the BT side
154
- next if (hm_class = hm.last&.klass) == #{model.name}
154
+ next if (hm_class = hm.last&.klass) == ::#{model.name}
155
155
 
156
156
  callbacks[hm_name = hm_class.name.split('::').last] = hm_class
157
157
  if (through = hm.last.options[:through]&.to_s) # has_many :through (HMT)
@@ -180,7 +180,7 @@ erDiagram
180
180
  'time without time zone' => 'time',
181
181
  'time with time zone' => 'time' }[dt] || dt&.tr(' ', '_') || 'int'
182
182
  end
183
- callbacks.merge({#{model_short_name.inspect} => #{model.name}}).each do |cb_k, cb_class|
183
+ callbacks.merge({#{model_short_name.inspect} => ::#{model.name}}).each do |cb_k, cb_class|
184
184
  cb_relation = ::Brick.relations[cb_class.table_name]
185
185
  pkeys = cb_relation[:pkey]&.first&.last
186
186
  fkeys = cb_relation[:fks]&.values&.each_with_object([]) { |fk, s| s << fk[:fk] if fk.fetch(:is_bt, nil) }
@@ -211,7 +211,7 @@ erDiagram
211
211
  %>
212
212
  </div>#{
213
213
  add_column = false # For the moment, disable all schema modification things
214
- "<%= brick_add_column(#{model.name}, #{prefix.inspect}).html_safe %>" unless add_column == false}
214
+ "<%= brick_add_column(::#{model.name}, #{prefix.inspect}).html_safe %>" unless add_column == false}
215
215
  </div>
216
216
  "
217
217
  end
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 236
8
+ TINY = 239
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
@@ -280,7 +280,7 @@ to instead be this:
280
280
  else
281
281
  puts "to support the #{model.name} model, you can add this into your brick.rb:
282
282
  ::Brick.polymorphics = { \"#{model.table_name}.#{a.name}\" =>
283
- #{hm_models.map(&:name).inspect}
283
+ #{hm_models.map { |m| "::#{m.name}" }.inspect}
284
284
  }"
285
285
  puts "and it will \"cement\" these options into place, and avoid this lookup process.\n"
286
286
  end
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.236
4
+ version: 1.0.239
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-12 00:00:00.000000000 Z
11
+ date: 2025-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -261,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
261
  - !ruby/object:Gem::Version
262
262
  version: 1.3.6
263
263
  requirements: []
264
- rubygems_version: 3.2.33
264
+ rubygems_version: 3.4.19
265
265
  signing_key:
266
266
  specification_version: 4
267
267
  summary: Create a Rails app from data alone