brick 1.0.47 → 1.0.48
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 +4 -4
- data/lib/brick/extensions.rb +14 -8
- data/lib/brick/frameworks/rails/engine.rb +2 -2
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +80 -46
- metadata +2 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9c3989f395bc81df36b3f295c72029e92911bd24f8d146db5627fb29c1875f4
|
|
4
|
+
data.tar.gz: 97ae12a1562f9f9bae5f401016e219a5ad58218068f80d7fc0e732d61c4f3f90
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c64d02f90b992640698523190a920467204a2fbb40fb9e21a3e7872ae469db3506bdf7fb535e54cd33157feb93ed43c2d1c11b2bea952bc9f034ac7e7dfb6b06
|
|
7
|
+
data.tar.gz: 6c01156b2b35f387e531ed6835a7517f5249b72ec53bb23d5d965c4b298a443d9a62e5694f9c1b4587f6ab04ef30590d7d9077e13c66b651ee8ed12b76282932
|
data/lib/brick/extensions.rb
CHANGED
|
@@ -619,7 +619,7 @@ Module.class_exec do
|
|
|
619
619
|
else
|
|
620
620
|
ActiveSupport::Inflector.pluralize(singular_table_name)
|
|
621
621
|
end
|
|
622
|
-
if ::Brick.
|
|
622
|
+
if ::Brick.apartment_multitenant &&
|
|
623
623
|
Apartment.excluded_models.include?(table_name.singularize.camelize)
|
|
624
624
|
schema_name = Apartment.default_schema
|
|
625
625
|
end
|
|
@@ -654,7 +654,7 @@ class Object
|
|
|
654
654
|
private
|
|
655
655
|
|
|
656
656
|
def build_model(schema_name, inheritable_name, model_name, singular_table_name, table_name, relations, matching)
|
|
657
|
-
if ::Brick.
|
|
657
|
+
if ::Brick.apartment_multitenant &&
|
|
658
658
|
schema_name == Apartment.default_schema
|
|
659
659
|
relation = relations["#{schema_name}.#{matching}"]
|
|
660
660
|
end
|
|
@@ -665,7 +665,7 @@ class Object
|
|
|
665
665
|
schema_name
|
|
666
666
|
else
|
|
667
667
|
matching = "#{schema_name}.#{matching}"
|
|
668
|
-
(Brick.db_schemas[schema_name] ||= self.const_get(schema_name.
|
|
668
|
+
(Brick.db_schemas[schema_name] ||= self.const_get(schema_name.camelize))
|
|
669
669
|
end
|
|
670
670
|
"#{schema_module&.name}::#{inheritable_name || model_name}"
|
|
671
671
|
end
|
|
@@ -846,7 +846,7 @@ class Object
|
|
|
846
846
|
if (inverse = assoc[:inverse])
|
|
847
847
|
# If it's multitenant with something like: public.____ ...
|
|
848
848
|
if (it_parts = inverse_table.split('.')).length > 1 &&
|
|
849
|
-
::Brick.
|
|
849
|
+
::Brick.apartment_multitenant &&
|
|
850
850
|
it_parts.first == Apartment.default_schema
|
|
851
851
|
it_parts.shift # ... then ditch the generic schema name
|
|
852
852
|
end
|
|
@@ -1142,7 +1142,8 @@ module ActiveRecord::ConnectionHandling
|
|
|
1142
1142
|
end
|
|
1143
1143
|
# Load the initializer for the Apartment gem a little early so that if .excluded_models and
|
|
1144
1144
|
# .default_schema are specified then we can work with non-tenanted models more appropriately
|
|
1145
|
-
|
|
1145
|
+
apartment = Object.const_defined?('Apartment')
|
|
1146
|
+
if apartment && File.exist?(apartment_initializer = Rails.root.join('config/initializers/apartment.rb'))
|
|
1146
1147
|
load apartment_initializer
|
|
1147
1148
|
apartment_excluded = Apartment.excluded_models
|
|
1148
1149
|
end
|
|
@@ -1345,17 +1346,20 @@ module ActiveRecord::ConnectionHandling
|
|
|
1345
1346
|
end
|
|
1346
1347
|
end
|
|
1347
1348
|
|
|
1348
|
-
apartment = Object.const_defined?('Apartment') && Apartment
|
|
1349
1349
|
tables = []
|
|
1350
1350
|
views = []
|
|
1351
1351
|
relations.each do |k, v|
|
|
1352
1352
|
name_parts = k.split('.')
|
|
1353
|
+
idx = 1
|
|
1354
|
+
name_parts = name_parts.map do |x|
|
|
1355
|
+
((idx += 1) < name_parts.length ? x.singularize : x).camelize
|
|
1356
|
+
end
|
|
1353
1357
|
if v.key?(:isView)
|
|
1354
1358
|
views
|
|
1355
1359
|
else
|
|
1356
1360
|
name_parts.shift if apartment && name_parts.length > 1 && name_parts.first == Apartment.default_schema
|
|
1357
1361
|
tables
|
|
1358
|
-
end << name_parts.
|
|
1362
|
+
end << name_parts.join('::')
|
|
1359
1363
|
end
|
|
1360
1364
|
unless tables.empty?
|
|
1361
1365
|
puts "\nClasses that can be built from tables:"
|
|
@@ -1437,7 +1441,7 @@ module Brick
|
|
|
1437
1441
|
unless (cnstr_name = fk[5])
|
|
1438
1442
|
# For any appended references (those that come from config), arrive upon a definitely unique constraint name
|
|
1439
1443
|
pri_tbl = is_class ? fk[4][:class].underscore : pri_tbl
|
|
1440
|
-
pri_tbl = "#{bt_assoc_name}_#{pri_tbl}" if pri_tbl
|
|
1444
|
+
pri_tbl = "#{bt_assoc_name}_#{pri_tbl}" if pri_tbl&.singularize != bt_assoc_name
|
|
1441
1445
|
cnstr_base = cnstr_name = "(brick) #{for_tbl}_#{pri_tbl}"
|
|
1442
1446
|
cnstr_added_num = 1
|
|
1443
1447
|
cnstr_name = "#{cnstr_base}_#{cnstr_added_num += 1}" while bts&.key?(cnstr_name) || hms&.key?(cnstr_name)
|
|
@@ -1463,6 +1467,8 @@ module Brick
|
|
|
1463
1467
|
return
|
|
1464
1468
|
end
|
|
1465
1469
|
end
|
|
1470
|
+
return unless bts # Rails 5.0 and older can have bts end up being nil
|
|
1471
|
+
|
|
1466
1472
|
if (assoc_bt = bts[cnstr_name])
|
|
1467
1473
|
if is_polymorphic
|
|
1468
1474
|
# Assuming same fk (don't yet support composite keys for polymorphics)
|
|
@@ -162,7 +162,7 @@ module Brick
|
|
|
162
162
|
schema_options = ::Brick.db_schemas.keys.each_with_object(+'') { |v, s| s << "<option value=\"#{v}\">#{v}</option>" }.html_safe
|
|
163
163
|
# %%% If we are not auto-creating controllers (or routes) then omit by default, and if enabled anyway, such as in a development
|
|
164
164
|
# environment or whatever, then get either the controllers or routes list instead
|
|
165
|
-
apartment_default_schema = ::Brick.
|
|
165
|
+
apartment_default_schema = ::Brick.apartment_multitenant && Apartment.default_schema
|
|
166
166
|
table_options = (::Brick.relations.keys - ::Brick.config.exclude_tables).map do |tbl|
|
|
167
167
|
if (tbl_parts = tbl.split('.')).first == apartment_default_schema
|
|
168
168
|
tbl = tbl_parts.last
|
|
@@ -537,7 +537,7 @@ if (headerTop) {
|
|
|
537
537
|
k, id = @_brick_params.first
|
|
538
538
|
id = id.first if id.is_a?(Array) && id.length == 1
|
|
539
539
|
origin = (key_parts = k.split('.')).length == 1 ? #{model_name} : #{model_name}.reflect_on_association(key_parts.first).klass
|
|
540
|
-
if (destination_fk = Brick.relations[origin.table_name][:fks].values.find { |fk|
|
|
540
|
+
if (destination_fk = Brick.relations[origin.table_name][:fks].values.find { |fk| fk[:fk] == key_parts.last }) &&
|
|
541
541
|
(obj = (destination = origin.reflect_on_association(destination_fk[:assoc_name])&.klass)&.find(id)) %>
|
|
542
542
|
<h3>for <%= link_to \"#{"#\{obj.brick_descrip\} (#\{destination.name\})\""}, send(\"#\{destination.name.underscore.tr('/', '_')\}_path\".to_sym, id) %></h3><%
|
|
543
543
|
end
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
|
@@ -47,7 +47,6 @@ end
|
|
|
47
47
|
|
|
48
48
|
# Add left_outer_join! to Associations::JoinDependency and Relation::QueryMethods
|
|
49
49
|
if ActiveRecord.version < ::Gem::Version.new('5')
|
|
50
|
-
is_add_left_outer_join = true
|
|
51
50
|
::Brick::Util._patch_require(
|
|
52
51
|
'active_record/associations/join_dependency.rb', '/activerecord', # /associations
|
|
53
52
|
["def join_constraints(outer_joins)
|
|
@@ -140,6 +139,13 @@ module Brick
|
|
|
140
139
|
(@relations ||= {})[ActiveRecord::Base.connection_pool.object_id] ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = {} } }
|
|
141
140
|
end
|
|
142
141
|
|
|
142
|
+
def apartment_multitenant
|
|
143
|
+
if @apartment_multitenant.nil?
|
|
144
|
+
@apartment_multitenant = ::Brick.config.schema_behavior[:multitenant] && Object.const_defined?('Apartment')
|
|
145
|
+
end
|
|
146
|
+
@apartment_multitenant
|
|
147
|
+
end
|
|
148
|
+
|
|
143
149
|
# If multitenancy is enabled, a list of non-tenanted "global" models
|
|
144
150
|
def non_tenanted_models
|
|
145
151
|
@pending_models ||= {}
|
|
@@ -451,7 +457,7 @@ In config/initializers/brick.rb appropriate entries would look something like:
|
|
|
451
457
|
::Brick.relations.each do |rel_name, v|
|
|
452
458
|
rel_name = rel_name.split('.').map(&:underscore)
|
|
453
459
|
schema_names = rel_name[0..-2]
|
|
454
|
-
schema_names.shift if ::Brick.
|
|
460
|
+
schema_names.shift if ::Brick.apartment_multitenant && schema_names.first == Apartment.default_schema
|
|
455
461
|
k = rel_name.last
|
|
456
462
|
unless existing_controllers.key?(controller_name = k.pluralize)
|
|
457
463
|
options = {}
|
|
@@ -481,7 +487,8 @@ require 'brick/version_number'
|
|
|
481
487
|
# Older versions of ActiveRecord would only show more serious error information from "panic" level, which is
|
|
482
488
|
# a level only available in Postgres 12 and older. This patch will allow older and newer versions of Postgres
|
|
483
489
|
# to work along with fairly old versions of Rails.
|
|
484
|
-
if Object.const_defined?('PG::VERSION')
|
|
490
|
+
if (is_postgres = (Object.const_defined?('PG::VERSION') || Gem::Specification.find_all_by_name('pg').present?)) &&
|
|
491
|
+
ActiveRecord.version < ::Gem::Version.new('4.2.6')
|
|
485
492
|
::Brick::Util._patch_require(
|
|
486
493
|
'active_record/connection_adapters/postgresql_adapter.rb', '/activerecord', ["'panic'", "'error'"]
|
|
487
494
|
)
|
|
@@ -489,13 +496,28 @@ end
|
|
|
489
496
|
|
|
490
497
|
require 'active_record'
|
|
491
498
|
require 'active_record/relation'
|
|
492
|
-
|
|
499
|
+
# To support adding left_outer_join
|
|
500
|
+
require 'active_record/relation/query_methods' if ActiveRecord.version < ::Gem::Version.new('5')
|
|
501
|
+
require 'rails/railtie' if ActiveRecord.version < ::Gem::Version.new('4.2')
|
|
493
502
|
|
|
494
503
|
# Rake tasks
|
|
495
504
|
class Railtie < Rails::Railtie
|
|
496
505
|
Dir.glob("#{File.expand_path(__dir__)}/brick/tasks/**/*.rake").each { |task| load task }
|
|
497
506
|
end
|
|
498
507
|
|
|
508
|
+
# Rails < 4.2 does not have env
|
|
509
|
+
module Rails
|
|
510
|
+
unless respond_to?(:env)
|
|
511
|
+
def self.env
|
|
512
|
+
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
def self.env=(environment)
|
|
516
|
+
@_env = ActiveSupport::StringInquirer.new(environment)
|
|
517
|
+
end
|
|
518
|
+
end
|
|
519
|
+
end
|
|
520
|
+
|
|
499
521
|
# Major compatibility fixes for ActiveRecord < 4.2
|
|
500
522
|
# ================================================
|
|
501
523
|
ActiveSupport.on_load(:active_record) do
|
|
@@ -510,6 +532,15 @@ ActiveSupport.on_load(:active_record) do
|
|
|
510
532
|
end
|
|
511
533
|
end
|
|
512
534
|
end
|
|
535
|
+
# ActiveRecord < 4.2 does not have default_timezone
|
|
536
|
+
# :singleton-method:
|
|
537
|
+
# Determines whether to use Time.utc (using :utc) or Time.local (using :local) when pulling
|
|
538
|
+
# dates and times from the database. This is set to :utc by default.
|
|
539
|
+
unless respond_to?(:default_timezone)
|
|
540
|
+
puts "ADDING!!! 4.w"
|
|
541
|
+
mattr_accessor :default_timezone, instance_writer: false
|
|
542
|
+
self.default_timezone = :utc
|
|
543
|
+
end
|
|
513
544
|
end
|
|
514
545
|
|
|
515
546
|
# Rails < 4.0 cannot do #find_by, #find_or_create_by, or do #pluck on multiple columns, so here are the patches:
|
|
@@ -715,58 +746,60 @@ ActiveSupport.on_load(:active_record) do
|
|
|
715
746
|
end
|
|
716
747
|
end
|
|
717
748
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
[info] + child.children.flat_map { |c| make_left_outer_joins(child, c) }
|
|
729
|
-
end
|
|
749
|
+
# Final pieces for left_outer_joins support, which was derived from this commit:
|
|
750
|
+
# https://github.com/rails/rails/commit/3f46ef1ddab87482b730a3f53987e04308783d8b
|
|
751
|
+
module Associations
|
|
752
|
+
class JoinDependency
|
|
753
|
+
def make_left_outer_joins(parent, child)
|
|
754
|
+
tables = child.tables
|
|
755
|
+
join_type = Arel::Nodes::OuterJoin
|
|
756
|
+
info = make_constraints parent, child, tables, join_type
|
|
757
|
+
|
|
758
|
+
[info] + child.children.flat_map { |c| make_left_outer_joins(child, c) }
|
|
730
759
|
end
|
|
731
760
|
end
|
|
732
|
-
|
|
733
|
-
|
|
761
|
+
end
|
|
762
|
+
module Querying
|
|
763
|
+
delegate :left_outer_joins, to: :all
|
|
764
|
+
end
|
|
765
|
+
class Relation
|
|
766
|
+
unless MULTI_VALUE_METHODS.include?(:left_outer_joins)
|
|
767
|
+
_multi_value_methods = MULTI_VALUE_METHODS + [:left_outer_joins]
|
|
768
|
+
send(:remove_const, :MULTI_VALUE_METHODS)
|
|
769
|
+
MULTI_VALUE_METHODS = _multi_value_methods
|
|
734
770
|
end
|
|
735
|
-
|
|
736
|
-
|
|
771
|
+
end
|
|
772
|
+
module QueryMethods
|
|
773
|
+
attr_writer :left_outer_joins_values
|
|
774
|
+
def left_outer_joins_values
|
|
775
|
+
@left_outer_joins_values ||= []
|
|
737
776
|
end
|
|
738
|
-
module QueryMethods
|
|
739
|
-
attr_writer :left_outer_joins_values
|
|
740
|
-
def left_outer_joins_values
|
|
741
|
-
@left_outer_joins_values ||= []
|
|
742
|
-
end
|
|
743
777
|
|
|
744
|
-
|
|
745
|
-
|
|
778
|
+
def left_outer_joins(*args)
|
|
779
|
+
check_if_method_has_arguments!(:left_outer_joins, args)
|
|
746
780
|
|
|
747
|
-
|
|
748
|
-
|
|
781
|
+
args.compact!
|
|
782
|
+
args.flatten!
|
|
749
783
|
|
|
750
|
-
|
|
751
|
-
|
|
784
|
+
spawn.left_outer_joins!(*args)
|
|
785
|
+
end
|
|
752
786
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
787
|
+
def left_outer_joins!(*args) # :nodoc:
|
|
788
|
+
self.left_outer_joins_values += args
|
|
789
|
+
self
|
|
790
|
+
end
|
|
757
791
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
end
|
|
792
|
+
def build_left_outer_joins(manager, outer_joins)
|
|
793
|
+
buckets = outer_joins.group_by do |join|
|
|
794
|
+
case join
|
|
795
|
+
when Hash, Symbol, Array
|
|
796
|
+
:association_join
|
|
797
|
+
else
|
|
798
|
+
raise ArgumentError, 'only Hash, Symbol and Array are allowed'
|
|
766
799
|
end
|
|
767
|
-
|
|
768
|
-
build_join_query(manager, buckets, Arel::Nodes::OuterJoin)
|
|
769
800
|
end
|
|
801
|
+
|
|
802
|
+
build_join_query(manager, buckets, Arel::Nodes::OuterJoin)
|
|
770
803
|
end
|
|
771
804
|
end
|
|
772
805
|
# (End of left_outer_joins support)
|
|
@@ -788,7 +821,8 @@ ActiveSupport.on_load(:active_record) do
|
|
|
788
821
|
end
|
|
789
822
|
|
|
790
823
|
# Do this earlier because stuff here gets mixed into JoinDependency::JoinAssociation and AssociationScope
|
|
791
|
-
if ActiveRecord.version < ::Gem::Version.new('5.0') && Object.const_defined?('PG::Connection')
|
|
824
|
+
if is_postgres && ActiveRecord.version < ::Gem::Version.new('5.0') # Was: && Object.const_defined?('PG::Connection')
|
|
825
|
+
require 'pg' # For ActiveRecord < 4.2
|
|
792
826
|
# Avoid pg gem deprecation warning: "You should use PG::Connection, PG::Result, and PG::Error instead"
|
|
793
827
|
PGconn = PG::Connection
|
|
794
828
|
PGresult = PG::Result
|
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.48
|
|
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-07-
|
|
11
|
+
date: 2022-07-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -17,9 +17,6 @@ dependencies:
|
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '4.2'
|
|
20
|
-
- - "<"
|
|
21
|
-
- !ruby/object:Gem::Version
|
|
22
|
-
version: '7.2'
|
|
23
20
|
type: :runtime
|
|
24
21
|
prerelease: false
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -27,9 +24,6 @@ dependencies:
|
|
|
27
24
|
- - ">="
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
26
|
version: '4.2'
|
|
30
|
-
- - "<"
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '7.2'
|
|
33
27
|
- !ruby/object:Gem::Dependency
|
|
34
28
|
name: fancy_gets
|
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|