brick 1.0.47 → 1.0.48

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4180c0164d7f086112339696df9d8fef2aeebcd32d9b81faf22d76ddc11815bc
4
- data.tar.gz: 823673bcbecc342f5df15e196ee65ad6f6ac0b75415514079c055af06d0ac7f6
3
+ metadata.gz: c9c3989f395bc81df36b3f295c72029e92911bd24f8d146db5627fb29c1875f4
4
+ data.tar.gz: 97ae12a1562f9f9bae5f401016e219a5ad58218068f80d7fc0e732d61c4f3f90
5
5
  SHA512:
6
- metadata.gz: 1d17b1abd64051066b71839095be1e672b897ad707a2d10f4ca4429131c894ee178711c873cef59957111704437b86b6322b8909ab5cc41cc955547146377dd8
7
- data.tar.gz: e210becff69096e73b9b7fa09bb4e1be6c36cd2982305b2c803c9c00e9d2b5b085857ea6edacc62498557cde928e2afbbb42ebbd137180385ec3a8a0c5efdf85
6
+ metadata.gz: c64d02f90b992640698523190a920467204a2fbb40fb9e21a3e7872ae469db3506bdf7fb535e54cd33157feb93ed43c2d1c11b2bea952bc9f034ac7e7dfb6b06
7
+ data.tar.gz: 6c01156b2b35f387e531ed6835a7517f5249b72ec53bb23d5d965c4b298a443d9a62e5694f9c1b4587f6ab04ef30590d7d9077e13c66b651ee8ed12b76282932
@@ -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.config.schema_behavior[:multitenant] && Object.const_defined?('Apartment') &&
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.config.schema_behavior[:multitenant] && Object.const_defined?('Apartment') &&
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.singularize.camelize))
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.config.schema_behavior[:multitenant] && Object.const_defined?('Apartment') &&
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
- if Object.const_defined?('Apartment') && File.exist?(apartment_initializer = Rails.root.join('config/initializers/apartment.rb'))
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.map { |x| x.singularize.camelize }.join('::')
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.singularize != bt_assoc_name
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.config.schema_behavior[:multitenant] && Object.const_defined?('Apartment') && Apartment.default_schema
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| puts fk.inspect; fk[:fk] == key_parts.last }) &&
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
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 47
8
+ TINY = 48
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
@@ -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.config.schema_behavior[:multitenant] && Object.const_defined?('Apartment') && schema_names.first == Apartment.default_schema
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') && ActiveRecord.version < ::Gem::Version.new('4.2.6')
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
- require 'active_record/relation/query_methods' if is_add_left_outer_join
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
- if is_add_left_outer_join
719
- # Final pieces for left_outer_joins support, which was derived from this commit:
720
- # https://github.com/rails/rails/commit/3f46ef1ddab87482b730a3f53987e04308783d8b
721
- module Associations
722
- class JoinDependency
723
- def make_left_outer_joins(parent, child)
724
- tables = child.tables
725
- join_type = Arel::Nodes::OuterJoin
726
- info = make_constraints parent, child, tables, join_type
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
- module Querying
733
- delegate :left_outer_joins, to: :all
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
- class Relation
736
- MULTI_VALUE_METHODS = MULTI_VALUE_METHODS + [:left_outer_joins] unless MULTI_VALUE_METHODS.include?(:left_outer_joins)
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
- def left_outer_joins(*args)
745
- check_if_method_has_arguments!(:left_outer_joins, args)
778
+ def left_outer_joins(*args)
779
+ check_if_method_has_arguments!(:left_outer_joins, args)
746
780
 
747
- args.compact!
748
- args.flatten!
781
+ args.compact!
782
+ args.flatten!
749
783
 
750
- spawn.left_outer_joins!(*args)
751
- end
784
+ spawn.left_outer_joins!(*args)
785
+ end
752
786
 
753
- def left_outer_joins!(*args) # :nodoc:
754
- self.left_outer_joins_values += args
755
- self
756
- end
787
+ def left_outer_joins!(*args) # :nodoc:
788
+ self.left_outer_joins_values += args
789
+ self
790
+ end
757
791
 
758
- def build_left_outer_joins(manager, outer_joins)
759
- buckets = outer_joins.group_by do |join|
760
- case join
761
- when Hash, Symbol, Array
762
- :association_join
763
- else
764
- raise ArgumentError, 'only Hash, Symbol and Array are allowed'
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.47
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-17 00:00:00.000000000 Z
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