brick 1.0.200 → 1.0.202
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +85 -47
- data/lib/brick/frameworks/rails/engine.rb +63 -46
- data/lib/brick/frameworks/rails/form_tags.rb +2 -2
- data/lib/brick/reflect_tables.rb +1 -1
- data/lib/brick/version_number.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80bf405e5c622d90a9e52cb94a9310740397a80c39add78a925a32f72c6ba75c
|
4
|
+
data.tar.gz: a434b961891001ba5c41767321392b390b0ab2c28bf1a5a323aae373686fe96f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2354f0b013d84f3cd0cd5a41656eefa39acaff5f7c0cc64d0be4382ef7f97ca60187895a2bcdb48d425145c5712511c5c4bde321b1f643a64c47f865597c565d
|
7
|
+
data.tar.gz: 9badc9353850afc991f7a17e964a262827ec23c7d6df62d4e4591d905460e21001f0c7e898f5b09ba1e41afbe077d39c24de03d82ffb8f6d7b43d66572f05f1f
|
data/lib/brick/extensions.rb
CHANGED
@@ -334,10 +334,10 @@ module ActiveRecord
|
|
334
334
|
end
|
335
335
|
|
336
336
|
# Providing a relation object allows auto-modules built from table name prefixes to work
|
337
|
-
def self._brick_index(mode = nil, separator = nil, relation = nil)
|
337
|
+
def self._brick_index(mode = nil, separator = nil, relation = nil, not_path = nil)
|
338
338
|
return if abstract_class?
|
339
339
|
|
340
|
-
::Brick._brick_index(table_name, mode, separator, relation)
|
340
|
+
::Brick._brick_index(table_name, mode, separator, relation, not_path)
|
341
341
|
end
|
342
342
|
|
343
343
|
def self.brick_import_template
|
@@ -1345,7 +1345,7 @@ end
|
|
1345
1345
|
((filename = ActiveSupport::Dependencies.search_for_file(desired_classname.underscore) ||
|
1346
1346
|
(self != Object && ActiveSupport::Dependencies.search_for_file((desired_classname = requested).underscore))
|
1347
1347
|
) && (require_dependency(filename) || true) &&
|
1348
|
-
((possible = self.const_get(args.first)) && possible.name == desired_classname)
|
1348
|
+
(!anonymous? && (possible = self.const_get(args.first)) && possible.name == desired_classname)
|
1349
1349
|
) ||
|
1350
1350
|
|
1351
1351
|
# If any class has turned up so far (and we're not in the middle of eager loading)
|
@@ -1366,13 +1366,14 @@ end
|
|
1366
1366
|
end
|
1367
1367
|
end
|
1368
1368
|
class_name = ::Brick.namify(requested)
|
1369
|
+
is_avo_present = Object.const_defined?('Avo') && ::Avo.respond_to?(:railtie_namespace)
|
1369
1370
|
# CONTROLLER
|
1370
1371
|
result = if ::Brick.enable_controllers? &&
|
1371
1372
|
is_controller && (plural_class_name = class_name[0..-11]).length.positive?
|
1372
1373
|
# Otherwise now it's up to us to fill in the gaps
|
1373
1374
|
controller_class_name = +''
|
1374
1375
|
full_class_name = +''
|
1375
|
-
unless self == Object
|
1376
|
+
unless self == Object || (is_avo_present && self.name == 'Avo')
|
1376
1377
|
controller_class_name << ((split_self_name&.first && split_self_name.join('::')) || self.name)
|
1377
1378
|
full_class_name << "::#{controller_class_name}"
|
1378
1379
|
controller_class_name << '::'
|
@@ -1432,58 +1433,43 @@ end
|
|
1432
1433
|
base_module.const_set(class_name.to_sym, (built_module = Module.new))
|
1433
1434
|
[built_module, "module #{possible_module}; end\n"]
|
1434
1435
|
|
1435
|
-
# AVO Resource
|
1436
|
-
elsif base_module == Object &&
|
1436
|
+
# AVO 2.x Resource
|
1437
|
+
elsif base_module == Object && is_avo_present && requested.end_with?('Resource') &&
|
1437
1438
|
# Expect that anything called MotorResource or SpinaResource could be from those administrative gems
|
1438
|
-
requested.length > 8 && ['MotorResource', 'SpinaResource'].exclude?(requested)
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
if (f = f.strip).start_with?('field ')
|
1446
|
-
f = f[6..-1].split(',')
|
1447
|
-
s << [f.first[1..-1].to_sym, [f[1][1..-1].split(': :').map(&:to_sym)].to_h]
|
1448
|
-
end
|
1449
|
-
end || []
|
1450
|
-
built_resource = Class.new(Avo::BaseResource) do |new_resource_class|
|
1451
|
-
self.model_class = model
|
1452
|
-
self.title = :brick_descrip
|
1453
|
-
self.includes = []
|
1454
|
-
if (!model.is_view? && mod_pk = model.primary_key)
|
1455
|
-
field((mod_pk.is_a?(Array) ? mod_pk.first : mod_pk).to_sym, { as: :id })
|
1456
|
-
end
|
1457
|
-
# Create a call such as: field :name, as: :text
|
1458
|
-
fields.each do |f|
|
1459
|
-
# Add proper types if this is a polymorphic belongs_to
|
1460
|
-
if f.last == { as: :belongs_to } &&
|
1461
|
-
(fk = ::Brick.relations[model.table_name][:fks].find { |k, v| v[:assoc_name] == f.first.to_s }) &&
|
1462
|
-
fk.last.fetch(:polymorphic, nil)
|
1463
|
-
poly_types = fk.last.fetch(:inverse_table, nil)&.each_with_object([]) do |poly_table, s|
|
1464
|
-
s << Object.const_get(::Brick.relations[poly_table][:class_name])
|
1465
|
-
end
|
1466
|
-
if poly_types.present?
|
1467
|
-
f.last[:polymorphic_as] = f.first
|
1468
|
-
f.last[:types] = poly_types
|
1469
|
-
end
|
1470
|
-
end
|
1471
|
-
self.send(:field, *f)
|
1472
|
-
end
|
1473
|
-
end
|
1474
|
-
Object.const_set(requested.to_sym, built_resource)
|
1475
|
-
[built_resource, nil]
|
1439
|
+
requested.length > 8 && ['MotorResource', 'SpinaResource'].exclude?(requested) &&
|
1440
|
+
(model = Object.const_get(requested[0..-9])) && model < ActiveRecord::Base
|
1441
|
+
built_resource = Class.new(Avo::BaseResource) do
|
1442
|
+
self.model_class = model
|
1443
|
+
self.title = :brick_descrip
|
1444
|
+
self.includes = []
|
1445
|
+
::Brick::ADD_AVO_FIELDS.call(self, model)
|
1476
1446
|
end
|
1447
|
+
base_module.const_set(requested.to_sym, built_resource)
|
1448
|
+
[built_resource, nil]
|
1449
|
+
|
1450
|
+
# AVO 3.x Resource
|
1451
|
+
elsif is_avo_present && self.name == 'Avo::Resources' &&
|
1452
|
+
(model = begin
|
1453
|
+
(model = Object.const_get(requested)) && model < ActiveRecord::Base
|
1454
|
+
model
|
1455
|
+
rescue
|
1456
|
+
end)
|
1457
|
+
[::Brick.avo_3x_resource(model, requested), nil]
|
1477
1458
|
|
1478
1459
|
# MODEL
|
1479
1460
|
elsif ::Brick.enable_models?
|
1461
|
+
# Avo sometimes tries to find a model class inside of the Avo namespace
|
1462
|
+
if is_avo_present && self.name == 'Avo'
|
1463
|
+
name = (base_module = Object).name
|
1464
|
+
end
|
1465
|
+
name ||= base_module.name
|
1480
1466
|
# Custom inheritable Brick base model?
|
1481
1467
|
class_name = (inheritable_name = class_name)[5..-1] if class_name.start_with?('Brick')
|
1482
1468
|
Object.send(:build_model, relations, base_module, name, class_name, inheritable_name)
|
1483
1469
|
end
|
1484
1470
|
if result
|
1485
1471
|
built_class, code = result
|
1486
|
-
puts "\n#{code}\n"
|
1472
|
+
puts "\n#{code}\n" if code
|
1487
1473
|
built_class
|
1488
1474
|
elsif !schema_name && ::Brick.config.sti_namespace_prefixes&.key?("::#{class_name}")
|
1489
1475
|
# module_prefixes = type_name.split('::')
|
@@ -1512,6 +1498,54 @@ end
|
|
1512
1498
|
end
|
1513
1499
|
end
|
1514
1500
|
|
1501
|
+
module Brick
|
1502
|
+
def self.avo_3x_resource(model, requested)
|
1503
|
+
built_resource = Class.new(Avo::BaseResource) do
|
1504
|
+
self.model_class = model
|
1505
|
+
self.title = :brick_descrip
|
1506
|
+
self.includes = []
|
1507
|
+
define_method :fields do # Have to be inside of a fields method
|
1508
|
+
::Brick::ADD_AVO_FIELDS.call(self, model)
|
1509
|
+
end
|
1510
|
+
end
|
1511
|
+
::Avo::Resources.const_set(requested.to_sym, built_resource)
|
1512
|
+
built_resource
|
1513
|
+
end
|
1514
|
+
end
|
1515
|
+
|
1516
|
+
::Brick::ADD_AVO_FIELDS = lambda do |obj, model|
|
1517
|
+
require 'generators/avo/resource_generator'
|
1518
|
+
field_generator = Generators::Avo::ResourceGenerator.new([''])
|
1519
|
+
field_generator.instance_variable_set(:@model, model)
|
1520
|
+
flds = field_generator.send(:generate_fields)&.split("\n")
|
1521
|
+
&.each_with_object([]) do |f, s|
|
1522
|
+
if (f = f.strip).start_with?('field ')
|
1523
|
+
f = f[6..-1].split(',')
|
1524
|
+
s << [f.first[1..-1].to_sym, [f[1][1..-1].split(': :').map(&:to_sym)].to_h]
|
1525
|
+
end
|
1526
|
+
end || []
|
1527
|
+
if (!model.is_view? && mod_pk = model.primary_key)
|
1528
|
+
obj.field((mod_pk.is_a?(Array) ? mod_pk.first : mod_pk).to_sym, **{ as: :id })
|
1529
|
+
end
|
1530
|
+
# Create a call such as: field :name, as: :text
|
1531
|
+
flds.each do |f|
|
1532
|
+
# Add proper types if this is a polymorphic belongs_to
|
1533
|
+
if f.last == { as: :belongs_to } &&
|
1534
|
+
(fk = ::Brick.relations[model.table_name][:fks].find { |k, v| v[:assoc_name] == f.first.to_s }) &&
|
1535
|
+
fk.last.fetch(:polymorphic, nil)
|
1536
|
+
poly_types = fk.last.fetch(:inverse_table, nil)&.each_with_object([]) do |poly_table, s|
|
1537
|
+
s << Object.const_get(::Brick.relations[poly_table][:class_name])
|
1538
|
+
end
|
1539
|
+
if poly_types.present?
|
1540
|
+
f.last[:polymorphic_as] = f.first
|
1541
|
+
f.last[:types] = poly_types
|
1542
|
+
end
|
1543
|
+
end
|
1544
|
+
kwargs = f.last.is_a?(Hash) ? f.pop : {}
|
1545
|
+
obj.send(:field, *f, **kwargs)
|
1546
|
+
end
|
1547
|
+
end
|
1548
|
+
|
1515
1549
|
class Object
|
1516
1550
|
class << self
|
1517
1551
|
|
@@ -2602,8 +2636,9 @@ class Object
|
|
2602
2636
|
assoc_parts[0].downcase! if assoc_parts[0] =~ /^[A-Z0-9_]+$/
|
2603
2637
|
assoc_name = assoc_parts.join('.')
|
2604
2638
|
else
|
2605
|
-
|
2606
|
-
|
2639
|
+
last_class_name_part = ::Brick.relations[hm_assoc[:inverse_table]].fetch(:class_name, nil)&.split('::')&.last ||
|
2640
|
+
::Brick.namify(hm_assoc[:inverse_table], :underscore).split('.').last.singularize.camelize
|
2641
|
+
needs_class = assoc_name.singularize.camelize != last_class_name_part
|
2607
2642
|
end
|
2608
2643
|
[assoc_name, needs_class]
|
2609
2644
|
end
|
@@ -2672,6 +2707,9 @@ else
|
|
2672
2707
|
rescue ActiveRecord::NoDatabaseError
|
2673
2708
|
# ::Brick.is_db_present = false
|
2674
2709
|
end
|
2710
|
+
if Object.const_defined?('Avo') && ::Avo.respond_to?(:railtie_namespace)
|
2711
|
+
Module.class_exec &::Brick::ADD_CONST_MISSING
|
2712
|
+
end
|
2675
2713
|
conn
|
2676
2714
|
end
|
2677
2715
|
end
|
@@ -225,14 +225,6 @@ function linkSchemas() {
|
|
225
225
|
# Specific database tables and views to omit when auto-creating models
|
226
226
|
::Brick.exclude_tables = app.config.brick.fetch(:exclude_tables, [])
|
227
227
|
|
228
|
-
# Class for auto-generated models to inherit from
|
229
|
-
::Brick.models_inherit_from = app.config.brick.fetch(:models_inherit_from, nil) ||
|
230
|
-
begin
|
231
|
-
::ApplicationRecord
|
232
|
-
rescue StandardError => ex
|
233
|
-
::ActiveRecord::Base
|
234
|
-
end
|
235
|
-
|
236
228
|
# When table names have specific prefixes, automatically place them in their own module with a table_name_prefix.
|
237
229
|
::Brick.config.table_name_prefixes ||= app.config.brick.fetch(:table_name_prefixes, {})
|
238
230
|
|
@@ -296,13 +288,13 @@ function linkSchemas() {
|
|
296
288
|
end
|
297
289
|
|
298
290
|
module UrlHelpers
|
299
|
-
alias
|
291
|
+
alias _brick_resources_path resources_path
|
300
292
|
# Accommodate STI resources
|
301
|
-
def
|
302
|
-
resource ||= if (klass =
|
293
|
+
def resources_path(resource:, **kwargs)
|
294
|
+
resource ||= if (klass = resource.model_class)
|
303
295
|
Avo::App.resources.find { |r| r.model_class > klass }
|
304
296
|
end
|
305
|
-
|
297
|
+
_brick_resources_path(resource: resource, **kwargs)
|
306
298
|
end
|
307
299
|
end
|
308
300
|
|
@@ -329,31 +321,53 @@ function linkSchemas() {
|
|
329
321
|
# end
|
330
322
|
# end
|
331
323
|
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
324
|
+
if self.const_defined?('Resources') &&
|
325
|
+
self::Resources.const_defined?('ResourceManager') # Avo 3.x?
|
326
|
+
self::Resources::ResourceManager.class_exec do
|
327
|
+
class << self
|
328
|
+
alias _brick_fetch_resources fetch_resources
|
329
|
+
def fetch_resources
|
330
|
+
Avo._brick_avo_resources
|
331
|
+
_brick_fetch_resources
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
elsif self::App.respond_to?(:eager_load) # Avo 2.x (compatible with 2.20.0 and up)
|
336
|
+
App.class_exec do
|
337
|
+
class << self
|
338
|
+
alias _brick_eager_load eager_load
|
339
|
+
def eager_load(entity)
|
340
|
+
Avo._brick_avo_resources(true) if entity == :resources
|
341
|
+
_brick_eager_load(entity)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def self._brick_avo_resources(is_2x = nil)
|
348
|
+
possible_schema, _x1, _x2 = ::Brick.get_possible_schemas
|
349
|
+
if possible_schema
|
350
|
+
orig_tenant = Apartment::Tenant.current
|
351
|
+
Apartment::Tenant.switch!(possible_schema)
|
352
|
+
end
|
353
|
+
existing = Avo::BaseResource.descendants.each_with_object({}) do |r, s|
|
354
|
+
s[r.name[0..-9]] = nil if r.name.end_with?('Resource')
|
355
|
+
end
|
356
|
+
::Brick.relations.each do |k, v|
|
357
|
+
unless k.is_a?(Symbol) || existing.key?(class_name = v[:class_name]) || Brick.config.exclude_tables.include?(k) ||
|
358
|
+
class_name.blank? || class_name.include?('::') ||
|
359
|
+
['ActiveAdminComment', 'MotorAlert', 'MotorAlertLock', 'MotorApiConfig', 'MotorAudit', 'MotorConfig', 'MotorDashboard', 'MotorForm', 'MotorNote', 'MotorNoteTag', 'MotorNoteTagTag', 'MotorNotification', 'MotorQuery', 'MotorReminder', 'MotorResource', 'MotorTag', 'MotorTaggableTag'].include?(class_name)
|
360
|
+
if is_2x # Avo 2.x?
|
361
|
+
"::#{class_name}Resource".constantize
|
362
|
+
else # Avo 3.x
|
363
|
+
unless ::Avo::BaseResource.constants.include?(class_name.to_sym) ||
|
364
|
+
::Avo::Resources.constants.include?(class_name.to_sym)
|
365
|
+
::Brick.avo_3x_resource(Object.const_get(class_name), class_name)
|
352
366
|
end
|
353
|
-
Apartment::Tenant.switch!(orig_tenant) if orig_tenant
|
354
367
|
end
|
355
368
|
end
|
356
369
|
end
|
370
|
+
Apartment::Tenant.switch!(orig_tenant) if orig_tenant
|
357
371
|
end
|
358
372
|
|
359
373
|
# Add our schema link Javascript code when the TurboFrameWrapper is rendered so it ends up on all index / show / etc
|
@@ -407,20 +421,25 @@ window.addEventListener(\"popstate\", linkSchemas);
|
|
407
421
|
end
|
408
422
|
|
409
423
|
class Fields::IndexComponent
|
410
|
-
|
411
|
-
|
412
|
-
|
424
|
+
if respond_to?(:resource_view_path)
|
425
|
+
alias _brick_resource_view_path resource_view_path
|
426
|
+
def resource_view_path
|
427
|
+
mdl_class = @resource.respond_to?(:model_class) ? @resource.model_class : @resource.model&.class
|
428
|
+
return if mdl_class&.is_view?
|
413
429
|
|
414
|
-
|
430
|
+
_brick_resource_view_path
|
431
|
+
end
|
415
432
|
end
|
416
433
|
end
|
417
434
|
|
418
435
|
module Concerns::HasFields
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
436
|
+
class << self
|
437
|
+
if respond_to?(:field)
|
438
|
+
alias _brick_field field
|
439
|
+
def field(name, *args, **kwargs, &block)
|
440
|
+
kwargs.merge!(args.pop) if args.last.is_a?(Hash)
|
441
|
+
_brick_field(name, **kwargs, &block)
|
442
|
+
end
|
424
443
|
end
|
425
444
|
end
|
426
445
|
end
|
@@ -1634,10 +1653,8 @@ end
|
|
1634
1653
|
# path_options = [obj.#{pk}]
|
1635
1654
|
# path_options << { '_brick_schema': } if
|
1636
1655
|
options = {}
|
1637
|
-
|
1638
|
-
|
1639
|
-
options[:url] = send(\"#\{path_helper}_path\".to_sym, obj)
|
1640
|
-
end
|
1656
|
+
path_helper = obj.new_record? ? #{model_name}._brick_index : #{model_name}._brick_index(:singular)
|
1657
|
+
options[:url] = send(\"#\{path_helper}_path\".to_sym, obj) if ::Brick.config.path_prefix || (path_helper != obj.class.table_name)
|
1641
1658
|
%>
|
1642
1659
|
<br><br>
|
1643
1660
|
|
@@ -592,11 +592,11 @@ function onImagesLoaded(event) {
|
|
592
592
|
relation = ::Brick.relations.fetch(rel_name || klass.table_name, nil)
|
593
593
|
if (klass_or_obj&.is_a?(Class) && klass_or_obj < ActiveRecord::Base) ||
|
594
594
|
(klass_or_obj&.is_a?(ActiveRecord::Base) && klass_or_obj.new_record? && (klass_or_obj = klass_or_obj.class))
|
595
|
-
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}"
|
595
|
+
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, true), action: :index)}#{filter}"
|
596
596
|
lt_args = [text || "Index for #{klass_or_obj.name.pluralize}", path]
|
597
597
|
else
|
598
598
|
# 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
|
599
|
-
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}"
|
599
|
+
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, true), action: :show, id: klass_or_obj)}#{filter}"
|
600
600
|
lt_args = [text || "Show this #{klass_or_obj.class.name}", path]
|
601
601
|
end
|
602
602
|
kwargs.delete(:visited)
|
data/lib/brick/reflect_tables.rb
CHANGED
@@ -462,7 +462,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
462
462
|
v[:resource] = proposed_name_parts.last.underscore
|
463
463
|
if colliding_thing
|
464
464
|
message_start = if colliding_thing.is_a?(Module) && Object.const_defined?(:Rails) &&
|
465
|
-
colliding_thing.constants.find { |c| colliding_thing.const_get(c) < Rails::Application }
|
465
|
+
colliding_thing.constants.find { |c| colliding_thing.const_get(c) < ::Rails::Application }
|
466
466
|
"The module for the Rails application itself, \"#{colliding_thing.name}\","
|
467
467
|
else
|
468
468
|
"Non-AR #{colliding_thing.class.name.downcase} \"#{colliding_thing.name}\""
|
data/lib/brick/version_number.rb
CHANGED
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.202
|
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-
|
11
|
+
date: 2024-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|