brick 1.0.74 → 1.0.75
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acd5fdf68935981a46106c879f5ac1fb44ac790c269c3eb2c5429cd67880f916
|
4
|
+
data.tar.gz: 260ce60eeaf2e4b17ca5b5e76e54960c4d2685c9cb9d8549a35a16ce49b5a36c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00f45ff020fcd729c2115f6d9f6ab0ab588247b2d727de7e1bd6acf53fa685ef76eeecce181a7a0c4659d8156971f88466915749cfad44e993993179435acdbd
|
7
|
+
data.tar.gz: 74f0b40c44bae3729624ca0ba6a378f9067e4b0aa98460a03aa193e292432576327991d8c2a107317d8ce51ce223eee780a0d632d5805ca14b91a1b55388259f
|
data/lib/brick/extensions.rb
CHANGED
@@ -235,7 +235,7 @@ module ActiveRecord
|
|
235
235
|
|
236
236
|
def self.bt_link(assoc_name)
|
237
237
|
assoc_name = CGI.escapeHTML(assoc_name.to_s)
|
238
|
-
model_path = Rails.application.routes.url_helpers.send("#{_brick_index}_path".to_sym)
|
238
|
+
model_path = ::Rails.application.routes.url_helpers.send("#{_brick_index}_path".to_sym)
|
239
239
|
av_class = Class.new.extend(ActionView::Helpers::UrlHelper)
|
240
240
|
av_class.extend(ActionView::Helpers::TagHelper) if ActionView.version < ::Gem::Version.new('7')
|
241
241
|
link = av_class.link_to(name, model_path)
|
@@ -641,7 +641,7 @@ JOIN (SELECT #{selects.join(', ')}, COUNT(#{'DISTINCT ' if hm.options[:through]}
|
|
641
641
|
module_prefixes.unshift('') unless module_prefixes.first.blank?
|
642
642
|
module_name = module_prefixes[0..-2].join('::')
|
643
643
|
if (snp = ::Brick.config.sti_namespace_prefixes)&.key?("::#{module_name}::") || snp&.key?("#{module_name}::") ||
|
644
|
-
File.exist?(candidate_file = Rails.root.join('app/models' + module_prefixes.map(&:underscore).join('/') + '.rb'))
|
644
|
+
File.exist?(candidate_file = ::Rails.root.join('app/models' + module_prefixes.map(&:underscore).join('/') + '.rb'))
|
645
645
|
_brick_find_sti_class(type_name) # Find this STI class normally
|
646
646
|
else
|
647
647
|
# Build missing prefix modules if they don't yet exist
|
@@ -710,13 +710,17 @@ end
|
|
710
710
|
Module.class_exec do
|
711
711
|
alias _brick_const_missing const_missing
|
712
712
|
def const_missing(*args)
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
713
|
+
desired_classname = (self == Object) ? args.first.to_s : "#{name}::#{args.first}"
|
714
|
+
if ((is_defined = self.const_defined?(args.first)) && (possible = self.const_get(args.first)) && possible.name == desired_classname) ||
|
715
|
+
# Try to require the respective Ruby file
|
716
|
+
((filename = ActiveSupport::Dependencies.search_for_file(desired_classname.underscore) ||
|
717
|
+
(self != Object && ActiveSupport::Dependencies.search_for_file((desired_classname = args.first.to_s).underscore))
|
718
|
+
) && (require_dependency(filename) || true) &&
|
719
|
+
((possible = self.const_get(args.first)) && possible.name == desired_classname)
|
720
|
+
) ||
|
721
|
+
# If any class has turned up so far (and we're not in the middle of eager loading)
|
722
|
+
# then return what we've found.
|
723
|
+
(is_defined && !::Brick.is_eager_loading)
|
720
724
|
return possible
|
721
725
|
end
|
722
726
|
class_name = ::Brick.namify(args.first.to_s)
|
@@ -766,7 +770,7 @@ Module.class_exec do
|
|
766
770
|
(schema_name = [(singular_table_name = class_name.underscore),
|
767
771
|
(table_name = singular_table_name.pluralize),
|
768
772
|
::Brick.is_oracle ? class_name.upcase : class_name,
|
769
|
-
(plural_class_name = class_name.pluralize)].find { |s| Brick.db_schemas
|
773
|
+
(plural_class_name = class_name.pluralize)].find { |s| Brick.db_schemas&.include?(s) }&.camelize ||
|
770
774
|
(::Brick.config.sti_namespace_prefixes&.key?("::#{class_name}::") && class_name))
|
771
775
|
return self.const_get(schema_name) if self.const_defined?(schema_name)
|
772
776
|
|
@@ -789,7 +793,7 @@ Module.class_exec do
|
|
789
793
|
# module_prefixes = type_name.split('::')
|
790
794
|
# path = base_module.name.split('::')[0..-2] + []
|
791
795
|
# module_prefixes.unshift('') unless module_prefixes.first.blank?
|
792
|
-
# candidate_file = Rails.root.join('app/models' + module_prefixes.map(&:underscore).join('/') + '.rb')
|
796
|
+
# candidate_file = ::Rails.root.join('app/models' + module_prefixes.map(&:underscore).join('/') + '.rb')
|
793
797
|
base_module._brick_const_missing(*args)
|
794
798
|
# elsif base_module != Object
|
795
799
|
# module_parent.const_missing(*args)
|
@@ -811,7 +815,7 @@ class Object
|
|
811
815
|
schema_name = [(singular_schema_name = base_name.underscore),
|
812
816
|
(schema_name = singular_schema_name.pluralize),
|
813
817
|
base_name,
|
814
|
-
base_name.pluralize].find { |s| Brick.db_schemas
|
818
|
+
base_name.pluralize].find { |s| Brick.db_schemas&.include?(s) }
|
815
819
|
end
|
816
820
|
plural_class_name = ActiveSupport::Inflector.pluralize(model_name = class_name)
|
817
821
|
# If it's namespaced then we turn the first part into what would be a schema name
|
@@ -1434,6 +1438,27 @@ module ActiveRecord::ConnectionHandling
|
|
1434
1438
|
alias _brick_establish_connection establish_connection
|
1435
1439
|
def establish_connection(*args)
|
1436
1440
|
conn = _brick_establish_connection(*args)
|
1441
|
+
# Overwrite SQLite's #begin_db_transaction so it opens in IMMEDIATE mode instead of
|
1442
|
+
# the default DEFERRED mode.
|
1443
|
+
# https://discuss.rubyonrails.org/t/failed-write-transaction-upgrades-in-sqlite3/81480/2
|
1444
|
+
if ActiveRecord::Base.connection.adapter_name == 'SQLite'
|
1445
|
+
arca = ::ActiveRecord::ConnectionAdapters
|
1446
|
+
db_statements = arca::SQLite3::DatabaseStatements
|
1447
|
+
# Rails 7.1 and later
|
1448
|
+
if arca::AbstractAdapter.private_instance_methods.include?(:with_raw_connection)
|
1449
|
+
db_statements.define_method(:begin_db_transaction) do
|
1450
|
+
log("begin immediate transaction", "TRANSACTION") do
|
1451
|
+
with_raw_connection(allow_retry: true, uses_transaction: false) do |conn|
|
1452
|
+
conn.transaction(:immediate)
|
1453
|
+
end
|
1454
|
+
end
|
1455
|
+
end
|
1456
|
+
else # Rails < 7.1
|
1457
|
+
db_statements.define_method(:begin_db_transaction) do
|
1458
|
+
log('begin immediate transaction', 'TRANSACTION') { @connection.transaction(:immediate) }
|
1459
|
+
end
|
1460
|
+
end
|
1461
|
+
end
|
1437
1462
|
begin
|
1438
1463
|
_brick_reflect_tables
|
1439
1464
|
rescue ActiveRecord::NoDatabaseError
|
@@ -1447,13 +1472,13 @@ module ActiveRecord::ConnectionHandling
|
|
1447
1472
|
initializer_loaded = false
|
1448
1473
|
if (relations = ::Brick.relations).empty?
|
1449
1474
|
# If there's schema things configured then we only expect our initializer to be named exactly this
|
1450
|
-
if File.exist?(brick_initializer = Rails.root.join('config/initializers/brick.rb'))
|
1475
|
+
if File.exist?(brick_initializer = ::Rails.root.join('config/initializers/brick.rb'))
|
1451
1476
|
initializer_loaded = load brick_initializer
|
1452
1477
|
end
|
1453
1478
|
# Load the initializer for the Apartment gem a little early so that if .excluded_models and
|
1454
1479
|
# .default_schema are specified then we can work with non-tenanted models more appropriately
|
1455
1480
|
apartment = Object.const_defined?('Apartment')
|
1456
|
-
if apartment && File.exist?(apartment_initializer = Rails.root.join('config/initializers/apartment.rb'))
|
1481
|
+
if apartment && File.exist?(apartment_initializer = ::Rails.root.join('config/initializers/apartment.rb'))
|
1457
1482
|
load apartment_initializer
|
1458
1483
|
apartment_excluded = Apartment.excluded_models
|
1459
1484
|
end
|
@@ -1980,14 +2005,7 @@ module Brick
|
|
1980
2005
|
end
|
1981
2006
|
end
|
1982
2007
|
end
|
1983
|
-
|
1984
|
-
::Rails.configuration.instance_variable_get(:@autoloader) == :classic
|
1985
|
-
Rails.configuration.eager_load_namespaces.select { |ns| ns < Rails::Application }.each(&:eager_load!)
|
1986
|
-
else
|
1987
|
-
Zeitwerk::Loader.eager_load_all
|
1988
|
-
end
|
1989
|
-
abstract_activerecord_bases = ActiveRecord::Base.descendants.select { |ar| ar.abstract_class? }.map(&:name)
|
1990
|
-
# abstract_activerecord_bases << ActiveRecord::Base
|
2008
|
+
abstract_activerecord_bases = ::Brick.eager_load_classes(true)
|
1991
2009
|
models = if Dir.exist?(model_path = "#{rails_root}/app/models")
|
1992
2010
|
Dir["#{model_path}/**/*.rb"].each_with_object({}) do |v, s|
|
1993
2011
|
File.read(v).split("\n").each do |line|
|
@@ -72,7 +72,6 @@ module Brick
|
|
72
72
|
def set_brick_model(find_args)
|
73
73
|
# Need to return true if we can fill in the blanks for a missing one
|
74
74
|
# args will be something like: ["index", ["categories"]]
|
75
|
-
find_args[1] = find_args[1].each_with_object([]) { |a, s| s.concat(a.split('/')) }
|
76
75
|
if (class_name = find_args[1].last&.singularize)
|
77
76
|
find_args[1][find_args[1].length - 1] = class_name # Make sure the last item, defining the class name, is singular
|
78
77
|
if (model = find_args[1].map(&:camelize).join('::').constantize) && (
|
@@ -100,10 +99,13 @@ module Brick
|
|
100
99
|
def find_template(*args, **options)
|
101
100
|
unless (model_name = @_brick_model&.name) ||
|
102
101
|
(is_status = ::Brick.config.add_status && args[0..1] == ['status', ['brick_gem']]) ||
|
103
|
-
(is_orphans = ::Brick.config.add_orphans && args[0..1] == ['orphans', ['brick_gem']])
|
104
|
-
|
105
|
-
|
106
|
-
|
102
|
+
(is_orphans = ::Brick.config.add_orphans && args[0..1] == ['orphans', ['brick_gem']])
|
103
|
+
if (possible_template = _brick_find_template(*args, **options))
|
104
|
+
return possible_template
|
105
|
+
else
|
106
|
+
# Used to also have: ActionView.version < ::Gem::Version.new('5.0') &&
|
107
|
+
model_name = (args[1].is_a?(Array) ? set_brick_model(args) : nil)&.name
|
108
|
+
end
|
107
109
|
end
|
108
110
|
|
109
111
|
if @_brick_model
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -123,7 +123,7 @@ module Brick
|
|
123
123
|
end
|
124
124
|
|
125
125
|
class << self
|
126
|
-
attr_accessor :default_schema, :db_schemas, :routes_done, :is_oracle
|
126
|
+
attr_accessor :default_schema, :db_schemas, :routes_done, :is_oracle, :is_eager_loading
|
127
127
|
|
128
128
|
def set_db_schema(params = nil)
|
129
129
|
schema = (params ? params['_brick_schema'] : ::Brick.default_schema) || 'public'
|
@@ -495,6 +495,21 @@ In config/initializers/brick.rb appropriate entries would look something like:
|
|
495
495
|
VERSION::STRING
|
496
496
|
end
|
497
497
|
|
498
|
+
def eager_load_classes(do_ar_abstract_bases = false)
|
499
|
+
::Brick.is_eager_loading = true
|
500
|
+
if ::ActiveSupport.version < ::Gem::Version.new('6') ||
|
501
|
+
::Rails.configuration.instance_variable_get(:@autoloader) == :classic
|
502
|
+
::Rails.configuration.eager_load_namespaces.select { |ns| ns < ::Rails::Application }.each(&:eager_load!)
|
503
|
+
else
|
504
|
+
Zeitwerk::Loader.eager_load_all
|
505
|
+
end
|
506
|
+
abstract_ar_bases = if do_ar_abstract_bases
|
507
|
+
ActiveRecord::Base.descendants.select { |ar| ar.abstract_class? }.map(&:name)
|
508
|
+
end
|
509
|
+
::Brick.is_eager_loading = false
|
510
|
+
abstract_ar_bases
|
511
|
+
end
|
512
|
+
|
498
513
|
def display_classes(rels, max_length)
|
499
514
|
rels.sort.each do |rel|
|
500
515
|
puts "#{rel.first}#{' ' * (max_length - rel.first.length)} /#{rel.last}"
|
@@ -593,12 +608,12 @@ require 'active_record/relation/query_methods' if ActiveRecord.version < ::Gem::
|
|
593
608
|
require 'rails/railtie' if ActiveRecord.version < ::Gem::Version.new('4.2')
|
594
609
|
|
595
610
|
# Rake tasks
|
596
|
-
class Railtie < Rails::Railtie
|
611
|
+
class Railtie < ::Rails::Railtie
|
597
612
|
Dir.glob("#{File.expand_path(__dir__)}/brick/tasks/**/*.rake").each { |task| load task }
|
598
613
|
end
|
599
614
|
|
600
615
|
# Rails < 4.2 does not have env
|
601
|
-
module Rails
|
616
|
+
module ::Rails
|
602
617
|
unless respond_to?(:env)
|
603
618
|
def self.env
|
604
619
|
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
|
@@ -55,7 +55,7 @@ module Brick
|
|
55
55
|
# If Apartment is active, see if a default schema to analyse is indicated
|
56
56
|
|
57
57
|
# # Load all models
|
58
|
-
#
|
58
|
+
# ::Brick.eager_load_classes
|
59
59
|
|
60
60
|
if (tables = ::Brick.relations.reject { |k, v| v.key?(:isView) && v[:isView] == true }.map(&:first).sort).empty?
|
61
61
|
puts "No tables found in database #{ActiveRecord::Base.connection.current_database}."
|
@@ -16,12 +16,7 @@ module Brick
|
|
16
16
|
# %%% If Apartment is active and there's no schema_to_analyse, ask which schema they want
|
17
17
|
|
18
18
|
# Load all models
|
19
|
-
|
20
|
-
::Rails.configuration.instance_variable_get(:@autoloader) == :classic
|
21
|
-
Rails.configuration.eager_load_namespaces.select { |ns| ns < Rails::Application }.each(&:eager_load!)
|
22
|
-
else
|
23
|
-
Zeitwerk::Loader.eager_load_all
|
24
|
-
end
|
19
|
+
::Brick.eager_load_classes
|
25
20
|
|
26
21
|
# Generate a list of viable models that can be chosen
|
27
22
|
longest_length = 0
|
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.75
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorin Thwaits
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|