431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
# File 'lib/brick/extensions.rb', line 431
def const_missing(*args)
return self.const_get(args.first) if self.const_defined?(args.first)
return Object.const_get(args.first) if Object.const_defined?(args.first) unless self == Object
class_name = args.first.to_s
if !(is_found = ActiveSupport::Dependencies.search_for_file(class_name.underscore)) && (filepath = self.name&.split('::'))
filepath = (filepath[0..-2] + [class_name]).join('/').underscore + '.rb'
end
if is_found
return self._brick_const_missing(*args)
elsif ActiveSupport::Dependencies.search_for_file(filepath) my_const = parent.const_missing(class_name) return my_const
end
relations = ::Brick.instance_variable_get(:@relations)[ActiveRecord::Base.connection_pool.object_id] || {}
result = if ::Brick.enable_controllers? && class_name.end_with?('Controller') && (plural_class_name = class_name[0..-11]).length.positive?
if (model = plural_class_name.singularize.constantize)
build_controller(class_name, plural_class_name, model, relations)
end
elsif ::Brick.enable_models?
plural_class_name = ActiveSupport::Inflector.pluralize(model_name = class_name)
singular_table_name = ActiveSupport::Inflector.underscore(model_name)
table_name = if (base_model = ::Brick.sti_models[model_name]&.fetch(:base, nil))
base_model.table_name
else
ActiveSupport::Inflector.pluralize(singular_table_name)
end
if (matching = [table_name, singular_table_name, plural_class_name, model_name].find { |m| relations.key?(m) })
build_model(model_name, singular_table_name, table_name, relations, matching)
end
end
if result
built_class, code = result
puts "\n#{code}"
built_class
elsif ::Brick.config.sti_namespace_prefixes&.key?("::#{class_name}")
self._brick_const_missing(*args)
else
puts "MISSING! #{self.name} #{args.inspect} #{table_name}"
self._brick_const_missing(*args)
end
end
|