brick 1.0.109 → 1.0.110

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: 1621b6af75759b90c788ce080db85608731c2bfc026c82d7bcea011a89c2162e
4
- data.tar.gz: a4242388d2fa29a12229c620d91b5d572e9e2f7688783beb6963817cf3fac340
3
+ metadata.gz: 3d11240139b576ead983fbe9811f4476b8819878068c46db852b515fbc0849c6
4
+ data.tar.gz: 2db932779fcd8517f7e5be524ce387061d4e8cab193715be76893dc1e675d1c9
5
5
  SHA512:
6
- metadata.gz: fa089c1bc9663e764b783c639ca9ca24c18a5cbbc788281e11620b33277e87282b6e1a0195d12686b72f53a5ae4a5bcb9e8343e9ef9bb4d97f53fb69ad4619fe
7
- data.tar.gz: 784eed99a879191dff95b5dfd061f8025d52d3e30eb16b7a754b425c2f4ad58e03e8631949d807f130dc86e55cb3a5e08d215a3f1729b4465c58dc3cecffb96d
6
+ metadata.gz: dd22a1ab8d2b13f2d289fe02262ae8aecb3be921094bbb5dd0392fe5cd46ecadda259e72a18c3ecb7daea0fd5f5a50d697383a4bb949b068976e3b6007769d04
7
+ data.tar.gz: 39d26f6c99511d3651003c660fed495223ebd4fb34865b1eaa3b8554e294ed0fb3672b17e7dc43ca43fecbd1b7dda2ec6b9a4371025880e12c83694f45557173
@@ -261,9 +261,16 @@ module ActiveRecord
261
261
  assoc_html_name ? "#{assoc_name}-#{link}".html_safe : link
262
262
  end
263
263
 
264
- def self._brick_index(mode = nil, separator = '_')
264
+ # Providing a relation object allows auto-modules built from table name prefixes to work
265
+ def self._brick_index(mode = nil, separator = '_', relation = nil)
265
266
  tbl_parts = ((mode == :singular) ? table_name.singularize : table_name).split('.')
266
267
  tbl_parts.shift if ::Brick.apartment_multitenant && tbl_parts.length > 1 && tbl_parts.first == ::Brick.apartment_default_tenant
268
+ if (aps = relation&.fetch(:auto_prefixed_schema, nil)) && tbl_parts.last.start_with?(aps)
269
+ last_part = tbl_parts.last[aps.length..-1]
270
+ aps = aps[0..-2] if aps[-1] == '_'
271
+ tbl_parts[-1] = aps
272
+ tbl_parts << last_part
273
+ end
267
274
  tbl_parts.unshift(::Brick.config.path_prefix) if ::Brick.config.path_prefix
268
275
  index = tbl_parts.map(&:underscore).join(separator)
269
276
  # Rails applies an _index suffix to that route when the resource name is singular
@@ -1005,7 +1012,8 @@ Module.class_exec do
1005
1012
 
1006
1013
  # MODULE
1007
1014
  elsif (::Brick.enable_models? || ::Brick.enable_controllers?) && # Schema match?
1008
- base_module == Object && # %%% This works for Person::Person -- but also limits us to not being able to allow more than one level of namespacing
1015
+ # %%% This works for Person::Person -- but also limits us to not being able to allow more than one level of namespacing
1016
+ (base_module == Object || (camelize_prefix && base_module == Object.const_get(camelize_prefix))) &&
1009
1017
  (schema_name = [(singular_table_name = class_name.underscore),
1010
1018
  (table_name = singular_table_name.pluralize),
1011
1019
  ::Brick.is_oracle ? class_name.upcase : class_name,
@@ -1437,7 +1445,7 @@ class Object
1437
1445
  is_postgres = ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
1438
1446
  is_mysql = ['Mysql2', 'Trilogy'].include?(ActiveRecord::Base.connection.adapter_name)
1439
1447
 
1440
- code = +"class #{class_name} < #{controller_base&.name || 'ApplicationController'}\n"
1448
+ code = +"class #{namespace}::#{class_name} < #{controller_base&.name || 'ApplicationController'}\n"
1441
1449
  built_controller = Class.new(controller_base || ActionController::Base) do |new_controller_class|
1442
1450
  (namespace || Object).const_set(class_name.to_sym, new_controller_class)
1443
1451
 
@@ -2272,11 +2280,20 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
2272
2280
  schema_names.shift if ::Brick.apartment_multitenant && schema_names.first == ::Brick.apartment_default_tenant
2273
2281
  v[:schema] = schema_names.join('.') unless schema_names.empty?
2274
2282
  # %%% If more than one schema has the same table name, will need to add a schema name prefix to have uniqueness
2275
- v[:resource] = rel_name.last
2276
2283
  if (singular = rel_name.last.singularize).blank?
2277
2284
  singular = rel_name.last
2278
2285
  end
2279
- v[:class_name] = (schema_names + [singular]).map(&:camelize).join('::')
2286
+ name_parts = if (tnp = ::Brick.config.table_name_prefixes
2287
+ .find { |k1, _v1| singular.start_with?(k1) && singular.length > k1.length }
2288
+ ).present?
2289
+ v[:auto_prefixed_schema] = tnp.first
2290
+ v[:resource] = rel_name.last[(tnp_length = tnp.first.length)..-1]
2291
+ [tnp.last, singular[tnp_length..-1]]
2292
+ else
2293
+ v[:resource] = rel_name.last
2294
+ [singular]
2295
+ end
2296
+ v[:class_name] = (schema_names + name_parts).map(&:camelize).join('::')
2280
2297
  end
2281
2298
  ::Brick.load_additional_references if ::Brick.initializer_loaded
2282
2299
 
@@ -10,10 +10,13 @@ module Brick
10
10
  if (param === undefined || param === null || param === -1) {
11
11
  hrefParts = hrefParts[0].split(\"://\");
12
12
  var pathParts = hrefParts[hrefParts.length - 1].split(\"/\").filter(function (pp) {return pp !== \"\";});
13
- if (value === undefined)
13
+ if (value === undefined) {
14
14
  // A couple possibilities if it's namespaced, starting with two parts in the path -- and then try just one
15
- return [pathParts.slice(1, 3).join('/'), pathParts.slice(1, 2)[0]];
16
- else {
15
+ if (pathParts.length > 3)
16
+ return [pathParts.slice(1, 4).join('/'), pathParts.slice(1, 3).join('/')];
17
+ else
18
+ return [pathParts.slice(1, 3).join('/'), pathParts[1]];
19
+ } else {
17
20
  var queryString = param ? \"?\" + params.join(\"&\") : \"\";
18
21
  return hrefParts[0] + \"://\" + pathParts[0] + \"/\" + value + queryString;
19
22
  }
@@ -187,7 +190,8 @@ function linkSchemas() {
187
190
  s[r.name[0..-9]] = nil if r.name.end_with?('Resource')
188
191
  end
189
192
  ::Brick.relations.each do |k, v|
190
- unless existing.key?(class_name = v[:class_name]) || Brick.config.exclude_tables.include?(k) || class_name.blank?
193
+ unless existing.key?(class_name = v[:class_name]) || Brick.config.exclude_tables.include?(k) ||
194
+ class_name.blank? || class_name.include?('::')
191
195
  Object.const_get("#{class_name}Resource")
192
196
  end
193
197
  end
@@ -452,11 +456,22 @@ window.addEventListener(\"popstate\", linkSchemas);
452
456
  # %%% If we are not auto-creating controllers (or routes) then omit by default, and if enabled anyway, such as in a development
453
457
  # environment or whatever, then get either the controllers or routes list instead
454
458
  prefix = "#{::Brick.config.path_prefix}/" if ::Brick.config.path_prefix
455
- table_options = (::Brick.relations.keys - ::Brick.config.exclude_tables).each_with_object({}) do |tbl, s|
456
- if (tbl_parts = tbl.split('.')).first == apartment_default_schema
457
- tbl = tbl_parts.last
459
+ table_options = ::Brick.relations.each_with_object({}) do |rel, s|
460
+ next if ::Brick.config.exclude_tables.include?(rel.first)
461
+
462
+ tbl_parts = rel.first.split('.')
463
+ if (aps = rel.last.fetch(:auto_prefixed_schema, nil))
464
+ tbl_parts << tbl_parts.last[aps.length..-1]
465
+ aps = aps[0..-2] if aps[-1] == '_'
466
+ tbl_parts[-2] = aps
467
+ end
468
+ if tbl_parts.first == apartment_default_schema
469
+ tbl_parts.shift
458
470
  end
459
- s[tbl] = nil
471
+ # %%% When table_name_prefixes are use then during rendering empty non-TNP
472
+ # entries get added at some point when an attempt is made to find the table.
473
+ # Will have to hunt that down at some point.
474
+ s[tbl_parts.join('.')] = nil unless rel.last[:cols].empty?
460
475
  end.keys.sort.each_with_object(+'') do |v, s|
461
476
  s << "<option value=\"#{prefix}#{v.underscore.gsub('.', '/')}\">#{v}</option>"
462
477
  end.html_safe
@@ -881,7 +896,8 @@ if (grid) {
881
896
  // });
882
897
  }
883
898
  function setHeaderSizes() {
884
- document.getElementById(\"titleBox\").style.width = grid.clientWidth;
899
+ if (grid.clientWidth > window.outerWidth)
900
+ document.getElementById(\"titleBox\").style.width = grid.clientWidth;
885
901
  // console.log(\"start\");
886
902
  // See if the headerTop is already populated
887
903
  // %%% Grab the TRs from headerTop, clear it out, do this stuff, add them back
@@ -1136,12 +1152,13 @@ erDiagram
1136
1152
  <td><h1><%= td_count = 2
1137
1153
  model.name %></h1></td>
1138
1154
  <td id=\"imgErd\" title=\"Show ERD\"></td>
1139
- <% if Object.const_defined?('Avo') && ::Avo.respond_to?(:railtie_namespace)
1155
+ <% if Object.const_defined?('Avo') && ::Avo.respond_to?(:railtie_namespace) && model.name.exclude?('::')
1140
1156
  td_count += 1 %>
1141
1157
  <td><%= link_to_brick(
1142
1158
  avo_svg,
1143
- { index_proc: Proc.new do |avo_model|
1144
- ::Avo.railtie_routes_url_helpers.send(\"resources_#\{model.model_name.route_key}_path\".to_sym)
1159
+ { index_proc: Proc.new do |avo_model, relation|
1160
+ path_helper = \"resources_#\{relation.fetch(:auto_prefixed_schema, nil)}#\{model.model_name.route_key}_path\".to_sym
1161
+ ::Avo.railtie_routes_url_helpers.send(path_helper) if ::Avo.railtie_routes_url_helpers.respond_to?(path_helper)
1145
1162
  end,
1146
1163
  title: \"#\{model.name} in Avo\" }
1147
1164
  ) %></td>
@@ -1328,8 +1345,9 @@ erDiagram
1328
1345
  <% if Object.const_defined?('Avo') && ::Avo.respond_to?(:railtie_namespace) %>
1329
1346
  <td><%= link_to_brick(
1330
1347
  avo_svg,
1331
- { show_proc: Proc.new do |obj|
1332
- ::Avo.railtie_routes_url_helpers.send(\"resources_#\{obj.class.base_class.model_name.singular_route_key}_path\".to_sym, obj)
1348
+ { show_proc: Proc.new do |obj, relation|
1349
+ path_helper = \"resources_#\{relation.fetch(:auto_prefixed_schema, nil)}#\{obj.class.base_class.model_name.singular_route_key}_path\".to_sym
1350
+ ::Avo.railtie_routes_url_helpers.send(path_helper, obj) if ::Avo.railtie_routes_url_helpers.respond_to?(path_helper)
1333
1351
  end,
1334
1352
  title: \"#\{page_title} in Avo\" }
1335
1353
  ) %></td>
@@ -1408,8 +1426,8 @@ end
1408
1426
  \"<span class=\\\"orphan\\\">Orphaned ID: #\{val}</span>\".html_safe
1409
1427
  end %>
1410
1428
  <% else
1411
- col_type = col.sql_type == 'geography' ? col.sql_type : col.type
1412
- case (col_type ||= col.sql_type)
1429
+ col_type = col&.sql_type == 'geography' ? col.sql_type : col&.type
1430
+ case (col_type ||= col&.sql_type)
1413
1431
  when :string, :text %>
1414
1432
  <% if is_bcrypt?(val) # || .readonly?
1415
1433
  is_revert = false %>
@@ -1489,9 +1507,9 @@ end
1489
1507
  # association that points to an STI model then filtering for the __able_type column is done
1490
1508
  # with a .where(). And the polymorphic class name it points to is the base class name of
1491
1509
  # the STI model instead of its subclass.
1492
- if (poly_type = #{poly_type.inspect}) &&
1493
- @#{obj_name}.respond_to?(:#{@_brick_model.inheritance_column}) &&
1494
- (base_type = collection.where_values_hash[poly_type])
1510
+ poly_type = #{poly_type.inspect}
1511
+ if poly_type && @#{obj_name}.respond_to?(:#{@_brick_model.inheritance_column}) &&
1512
+ (base_type = collection.where_values_hash[poly_type])
1495
1513
  collection = collection.rewhere(poly_type => [base_type, @#{obj_name}.#{@_brick_model.inheritance_column}])
1496
1514
  end"
1497
1515
  end
@@ -162,8 +162,9 @@ module Brick::Rails::FormTags
162
162
  @_brick_model
163
163
  # If not provided, do a best-effort to automatically determine the resource class or object
164
164
  filter_parts = []
165
+ rel_name = nil
165
166
  klass_or_obj ||= begin
166
- klass, sti_type = ::Brick.ctrl_to_klass(controller_path)
167
+ klass, sti_type, rel_name = ::Brick.ctrl_to_klass(controller_path)
167
168
  if klass
168
169
  type_col = klass.inheritance_column # Usually 'type'
169
170
  filter_parts << "#{type_col}=#{sti_type}" if sti_type && klass.column_names.include?(type_col)
@@ -202,11 +203,11 @@ module Brick::Rails::FormTags
202
203
  app_routes = Rails.application.routes # In case we're operating in another engine, reference the application since Brick routes are placed there.
203
204
  if (klass_or_obj&.is_a?(Class) && klass_or_obj < ActiveRecord::Base) ||
204
205
  (klass_or_obj&.is_a?(ActiveRecord::Base) && klass_or_obj.new_record? && (klass_or_obj = klass_or_obj.class))
205
- path = (proc = kwargs[:index_proc]) ? proc.call(klass_or_obj) : "#{app_routes.path_for(controller: klass_or_obj.base_class._brick_index(nil, '/'), action: :index)}#{filter}"
206
+ path = (proc = kwargs[:index_proc]) ? proc.call(klass_or_obj, relation) : "#{app_routes.path_for(controller: klass_or_obj.base_class._brick_index(nil, '/', relation), action: :index)}#{filter}"
206
207
  lt_args = [text || "Index for #{klass_or_obj.name.pluralize}", path]
207
208
  else
208
209
  # If there are multiple incoming parameters then last one is probably the actual ID, and first few might be some nested tree of stuff leading up to it
209
- path = (proc = kwargs[:show_proc]) ? proc.call(klass_or_obj) : "#{app_routes.path_for(controller: klass_or_obj.class.base_class._brick_index(nil, '/'), action: :show, id: klass_or_obj)}#{filter}"
210
+ path = (proc = kwargs[:show_proc]) ? proc.call(klass_or_obj, relation) : "#{app_routes.path_for(controller: klass_or_obj.class.base_class._brick_index(nil, '/', relation), action: :show, id: klass_or_obj)}#{filter}"
210
211
  lt_args = [text || "Show this #{klass_or_obj.class.name}", path]
211
212
  end
212
213
  kwargs.delete(:visited)
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 109
8
+ TINY = 110
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
@@ -601,7 +601,7 @@ In config/initializers/brick.rb appropriate entries would look something like:
601
601
  def display_classes(prefix, rels, max_length)
602
602
  rels.sort.each do |rel|
603
603
  (::Brick.auto_models ||= []) << rel.first
604
- puts "#{rel.first}#{' ' * (max_length - rel.first.length)} /#{prefix}#{rel.last}"
604
+ puts "#{rel.first}#{' ' * (max_length - rel.first.length)} /#{prefix}#{"#{rel[1]}/" if rel[1]}#{rel.last}"
605
605
  end
606
606
  puts "\n"
607
607
  end
@@ -620,16 +620,21 @@ In config/initializers/brick.rb appropriate entries would look something like:
620
620
  end
621
621
 
622
622
  c_path_parts = ctrl_path.split('/')
623
+ found = nil
623
624
  while c_path_parts.present?
624
625
  possible_c_path = c_path_parts.join('.')
625
626
  possible_c_path_singular = c_path_parts[0..-2] + [c_path_parts.last.singularize]
626
627
  possible_sti = possible_c_path_singular.join('/').camelize
627
628
  break if (
628
- res_name = res_names[possible_c_path] ||
629
+ res_name = res_names[found = possible_c_path] ||
629
630
  ((klass = Brick.config.sti_namespace_prefixes.key?("::#{possible_sti}") && possible_sti.constantize) &&
630
631
  (sti_type = possible_sti)) ||
631
632
  # %%% Used to have the more flexible: (DidYouMean::SpellChecker.new(dictionary: res_names.keys).correct(possible_c_path)).first
632
- res_names[possible_c_path] || res_names[possible_c_path_singular.join('.')]
633
+ res_names[found = possible_c_path] || res_names[found = possible_c_path_singular.join('.')] ||
634
+ ((::Brick.config.table_name_prefixes.key?(tn_prefix = c_path_parts.first) ||
635
+ ::Brick.config.table_name_prefixes.key?(tn_prefix = "#{c_path_parts.first}_")) &&
636
+ res_names[found = tn_prefix + c_path_parts.last]
637
+ )
633
638
  ) &&
634
639
  (
635
640
  klass ||
@@ -638,7 +643,7 @@ In config/initializers/brick.rb appropriate entries would look something like:
638
643
  )
639
644
  c_path_parts.shift
640
645
  end
641
- [klass, sti_type]
646
+ [klass, sti_type, found]
642
647
  end
643
648
  end
644
649
 
@@ -657,10 +662,14 @@ In config/initializers/brick.rb appropriate entries would look something like:
657
662
  table_class_length = 38 # Length of "Classes that can be built from tables:"
658
663
  view_class_length = 37 # Length of "Classes that can be built from views:"
659
664
 
660
- brick_routes_create = lambda do |schema_name, res_name, options|
661
- if schema_name # && !Object.const_defined('Apartment')
662
- send(:namespace, schema_name) do
663
- send(:resources, res_name.to_sym, **options)
665
+ brick_namespace_create = lambda do |path_names, res_name, options|
666
+ if path_names&.present?
667
+ if (path_name = path_names.pop).is_a?(Array)
668
+ module_name = path_name[1]
669
+ path_name = path_name.first
670
+ end
671
+ send(:scope, { module: module_name || path_name, path: path_name, as: path_name }) do
672
+ brick_namespace_create.call(path_names, res_name, options)
664
673
  end
665
674
  else
666
675
  send(:resources, res_name.to_sym, **options)
@@ -676,13 +685,24 @@ In config/initializers/brick.rb appropriate entries would look something like:
676
685
  end
677
686
  versioned_views = {} # Track which views have already been done for each api_root
678
687
  ::Brick.relations.each do |k, v|
679
- next if !(controller_name = v.fetch(:resource, nil)&.pluralize) || existing_controllers.key?(controller_name)
680
-
681
- object_name = k.split('.').last # Take off any first schema part
682
688
  if (schema_name = v.fetch(:schema, nil))
683
689
  schema_prefix = "#{schema_name}."
684
690
  end
685
691
 
692
+ next if !(resource_name = v.fetch(:resource, nil)) ||
693
+ existing_controllers.key?(controller_name = (
694
+ resource_name = "#{schema_prefix&.tr('.', '/')}#{resource_name}"
695
+ ).pluralize)
696
+
697
+ object_name = k.split('.').last # Take off any first schema part
698
+
699
+ full_schema_prefix = if (aps = v.fetch(:auto_prefixed_schema, nil))
700
+ aps = aps[0..-2] if aps[-1] == '_'
701
+ (schema_prefix&.dup || +'') << "#{aps}."
702
+ else
703
+ schema_prefix
704
+ end
705
+
686
706
  # Track routes being built
687
707
  if (class_name = v.fetch(:class_name, nil))
688
708
  if v.key?(:isView)
@@ -691,26 +711,20 @@ In config/initializers/brick.rb appropriate entries would look something like:
691
711
  else
692
712
  table_class_length = class_name.length if class_name.length > table_class_length
693
713
  tables
694
- end << [class_name, "#{schema_prefix&.tr('.', '/')}#{v[:resource]}"]
714
+ end << [class_name, aps, resource_name]
695
715
  end
696
716
 
697
717
  options = {}
698
718
  options[:only] = [:index, :show] if v.key?(:isView)
699
719
 
700
720
  # First do the normal routes
701
- if path_prefix
702
- # Was: send(:scope, path: path_prefix) do
703
- send(:namespace, path_prefix) do
704
- brick_routes_create.call(schema_name, v[:resource], options)
705
- sti_subclasses.fetch(class_name, nil)&.each do |sc| # Add any STI subclass routes for this relation
706
- brick_routes_create.call(schema_name, sc.underscore.tr('/', '_').pluralize, options)
707
- end
708
- end
709
- else
710
- brick_routes_create.call(schema_name, v[:resource], options)
711
- sti_subclasses.fetch(class_name, nil)&.each do |sc| # Add any STI subclass routes for this relation
712
- brick_routes_create.call(schema_name, sc.underscore.tr('/', '_').pluralize, options)
713
- end
721
+ prefixes = []
722
+ prefixes << [aps, v[:class_name]&.split('::')[-2]&.underscore] if aps
723
+ prefixes << schema_name if schema_name
724
+ prefixes << path_prefix if path_prefix
725
+ brick_namespace_create.call(prefixes, v[:resource], options)
726
+ sti_subclasses.fetch(class_name, nil)&.each do |sc| # Add any STI subclass routes for this relation
727
+ brick_namespace_create.call(prefixes, sc.underscore.tr('/', '_').pluralize, options)
714
728
  end
715
729
 
716
730
  # Now the API routes if necessary
@@ -815,9 +829,8 @@ In config/initializers/brick.rb appropriate entries would look something like:
815
829
  # view_ver_num = if (first_part = k.split('_').first) =~ /^v[\d_]+/
816
830
  # first_part[1..-1].gsub('_', '.').to_i
817
831
  # end
818
-
819
832
  controller_name = if (last = view_relation.fetch(:resource, nil)&.pluralize)
820
- "#{schema_prefix}#{last}"
833
+ "#{full_schema_prefix}#{last}"
821
834
  else
822
835
  found
823
836
  end.tr('.', '/')
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.109
4
+ version: 1.0.110
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-01-27 00:00:00.000000000 Z
11
+ date: 2023-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord