brick 1.0.81 → 1.0.82

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: 2627490165a63200a49afb7707882489986217bc170491e88f64eb9faf880b6b
4
- data.tar.gz: f12adff07785ffd5c4a877f555cd7899de859f99ae9b18b84eda6f3d20ac5c15
3
+ metadata.gz: 74df340edd3b41626ea7f72409064b27ae10ddfd6eb41dd66ecc6704044156bd
4
+ data.tar.gz: 82181c7ffe7a26b6ab02bfc4faaedf031d78e5e4880f6316e1ea2143da8a9655
5
5
  SHA512:
6
- metadata.gz: f112e1bf44fc39e80bced64a2d9fb4dd16297e2c549f66d0842fb65d7f3644170fa18c3c784c59c5a93db57233a77bfa5f288dca89be1b3dec6172bb670f147b
7
- data.tar.gz: 0c2061b9b662c00aeb85a76db20fb59962302dd8b6ab17225ded332eadf4485392e3f5e44538b8f99d525666b8a036bb2fbd53a2604bbf7f69aca3ad8400fa4d
6
+ metadata.gz: 644d3d343e774f8682a575c8fad849c27ee60c279e30a689874b608f056b1aee39a936ec85e91878d2200deeaf49ad78188866b6548ccf6dae43fbadbe80752a
7
+ data.tar.gz: '09f1f3383f9db0f3519215bb372a238478a0ae5176090bd2992a4f43f6e41b8aaef9f2a449573413ee886cc08cd94b868e0ec81a822b20d8dd0cc9e4eebf635e'
@@ -59,6 +59,10 @@ end
59
59
 
60
60
  module ActiveRecord
61
61
  class Base
62
+ def self.is_brick?
63
+ instance_variables.include?(:@_brick_built) && instance_variable_get(:@_brick_built)
64
+ end
65
+
62
66
  def self._assoc_names
63
67
  @_assoc_names ||= {}
64
68
  end
@@ -521,7 +525,7 @@ module ActiveRecord
521
525
  # CUSTOM COLUMNS
522
526
  # ==============
523
527
  klass._br_cust_cols.each do |k, cc|
524
- if respond_to?(k) # Name already taken?
528
+ if rel_dupe.respond_to?(k) # Name already taken?
525
529
  # %%% Use ensure_unique here in this kind of fashion:
526
530
  # cnstr_name = ensure_unique(+"(brick) #{for_tbl}_#{pri_tbl}", bts, hms)
527
531
  # binding.pry
@@ -641,11 +645,13 @@ module ActiveRecord
641
645
  [a.table_name, a.foreign_key, a.source_reflection.macro]
642
646
  end
643
647
  next if bail_out
648
+
644
649
  # count_column is determined from the originating HMT member
645
650
  if (src_ref = hm.source_reflection).nil?
646
651
  puts "*** Warning: Could not determine destination model for this HMT association in model #{klass.name}:\n has_many :#{hm.name}, through: :#{hm.options[:through]}"
652
+ puts
647
653
  nix << k
648
- bail_out = true
654
+ next
649
655
  elsif src_ref.macro == :belongs_to # Traditional HMT using an associative table
650
656
  "br_t#{idx}.#{hm.foreign_key}"
651
657
  else # A HMT that goes HM -> HM, something like Categories -> Products -> LineItems
@@ -676,15 +682,15 @@ module ActiveRecord
676
682
  pri_tbl.table_name
677
683
  end
678
684
  on_clause = []
679
- if fk_col.is_a?(Array) # Composite key?
680
- fk_col.each_with_index { |fk_col_part, idx| on_clause << "#{tbl_alias}.#{fk_col_part} = #{pri_tbl_name}.#{pri_tbl.primary_key[idx]}" }
681
- selects = fk_col.dup
682
- else
683
- selects = [fk_col]
684
- on_clause << "#{tbl_alias}.#{fk_col} = #{pri_tbl_name}.#{pri_tbl.primary_key}"
685
- end
685
+ hm_selects = if fk_col.is_a?(Array) # Composite key?
686
+ fk_col.each_with_index { |fk_col_part, idx| on_clause << "#{tbl_alias}.#{fk_col_part} = #{pri_tbl_name}.#{pri_tbl.primary_key[idx]}" }
687
+ fk_col.dup
688
+ else
689
+ on_clause << "#{tbl_alias}.#{fk_col} = #{pri_tbl_name}.#{pri_tbl.primary_key}"
690
+ [fk_col]
691
+ end
686
692
  if poly_type
687
- selects << poly_type
693
+ hm_selects << poly_type
688
694
  on_clause << "#{tbl_alias}.#{poly_type} = '#{name}'"
689
695
  end
690
696
  unless from_clause
@@ -696,9 +702,9 @@ module ActiveRecord
696
702
  hm.table_name
697
703
  end
698
704
  end
699
- group_bys = ::Brick.is_oracle || is_mssql ? selects : (1..selects.length).to_a
705
+ group_bys = ::Brick.is_oracle || is_mssql ? hm_selects : (1..hm_selects.length).to_a
700
706
  join_clause = "LEFT OUTER
701
- JOIN (SELECT #{selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', ')}, COUNT(#{'DISTINCT ' if hm.options[:through]}#{count_column
707
+ JOIN (SELECT #{hm_selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', ')}, COUNT(#{'DISTINCT ' if hm.options[:through]}#{count_column
702
708
  }) AS c_t_ FROM #{from_clause || hm_table_name} GROUP BY #{group_bys.join(', ')}) #{tbl_alias}"
703
709
  joins!("#{join_clause} ON #{on_clause.join(' AND ')}")
704
710
  end
@@ -735,8 +741,10 @@ JOIN (SELECT #{selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', ')},
735
741
  else
736
742
  s << v
737
743
  end
738
- else # String stuff just comes straight through
744
+ else # String stuff (which defines a custom ORDER BY) just comes straight through
739
745
  s << v
746
+ # Avoid "PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list" in Postgres
747
+ selects << v if is_distinct
740
748
  end
741
749
  end
742
750
  order!(*final_order_by)
@@ -1138,6 +1146,7 @@ class Object
1138
1146
  end # class definition
1139
1147
  # Having this separate -- will this now work out better?
1140
1148
  built_model.class_exec do
1149
+ @_brick_built = true
1141
1150
  hmts&.each do |hmt_fk, hms|
1142
1151
  hmt_fk = hmt_fk.tr('.', '_')
1143
1152
  hms.each do |hm|
@@ -130,15 +130,15 @@ module Brick
130
130
  next unless @_brick_model.instance_methods.include?(through) &&
131
131
  (associative = @_brick_model._br_associatives.fetch(hm.first, nil))
132
132
 
133
- tbl_nm = if hm_assoc.options[:source]
134
- associative.klass.reflect_on_association(hm_assoc.options[:source]).inverse_of&.name
133
+ tbl_nm = if (source = hm_assoc.source_reflection).macro == :belongs_to
134
+ hm_assoc.through_reflection&.name # for standard HMT, which is HM -> BT
135
135
  else
136
- associative.name
136
+ source.inverse_of&.name # For HM -> HM style HMT
137
137
  end
138
138
  # If there is no inverse available for the source belongs_to association, make one based on the class name
139
139
  unless tbl_nm
140
140
  tbl_nm = associative.class_name.underscore
141
- tbl_nm.slice!(0) if tbl_nm[0] == ('/')
141
+ tbl_nm.slice!(0) if tbl_nm[0] == '/'
142
142
  tbl_nm = tbl_nm.tr('/', '_').pluralize
143
143
  end
144
144
  "'#{tbl_nm}.#{associative.foreign_key}'"
@@ -1331,10 +1331,18 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1331
1331
  prepend ::Brick::RouteSet
1332
1332
  end
1333
1333
  # Do the root route before the Rails Welcome one would otherwise take precedence
1334
- unless (route = ::Brick.config.default_route_fallback).blank? ||
1335
- ::Rails.application.routes.named_routes.send(:routes)[:root]
1336
- ::Rails.application.routes.append do
1337
- send(:root, "#{route}#{'#index' unless route.index('#')}")
1334
+ if (route = ::Brick.config.default_route_fallback).present?
1335
+ action = "#{route}#{'#index' unless route.index('#')}"
1336
+ if ::Brick.config.path_prefix
1337
+ ::Rails.application.routes.append do
1338
+ send(:namespace, ::Brick.config.path_prefix) do
1339
+ send(:root, action)
1340
+ end
1341
+ end
1342
+ elsif ::Rails.application.routes.named_routes.send(:routes)[:root].nil?
1343
+ ::Rails.application.routes.append do
1344
+ send(:root, action)
1345
+ end
1338
1346
  end
1339
1347
  end
1340
1348
  end
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 81
8
+ TINY = 82
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
@@ -113,15 +113,15 @@ if Gem::Specification.all_names.any? { |g| g.start_with?('rails-') }
113
113
  require 'brick/frameworks/rails'
114
114
  end
115
115
  module Brick
116
- def self.sti_models
117
- @sti_models ||= {}
118
- end
116
+ class << self
117
+ def sti_models
118
+ @sti_models ||= {}
119
+ end
119
120
 
120
- def self.existing_stis
121
- @existing_stis ||= Brick.config.sti_namespace_prefixes.each_with_object({}) { |snp, s| s[snp.first[2..-1]] = snp.last unless snp.first.end_with?('::') }
122
- end
121
+ def existing_stis
122
+ @existing_stis ||= Brick.config.sti_namespace_prefixes.each_with_object({}) { |snp, s| s[snp.first[2..-1]] = snp.last unless snp.first.end_with?('::') }
123
+ end
123
124
 
124
- class << self
125
125
  attr_accessor :default_schema, :db_schemas, :routes_done, :is_oracle, :is_eager_loading, :auto_models
126
126
 
127
127
  def set_db_schema(params = nil)
@@ -203,11 +203,9 @@ module Brick
203
203
  skip_hms = {}
204
204
  hms.each do |hmt|
205
205
  if (through = hmt.last.options[:through])
206
- skip_hms[through] = nil # if hms[through]
207
- # binding.pry if !hms[through]
206
+ # ::Brick.relations[hmt.last.through_reflection.table_name]
207
+ skip_hms[through] = nil if hms[through] && model.is_brick?
208
208
  # End up with a hash of HMT names pointing to join-table associations
209
- # Last part was: hmt.last.name
210
- # Changed up because looking for: hms[:issue_issue_duplicates]
211
209
  model._br_associatives[hmt.first] = hms[through] # || hms["#{(opt = hmt.last.options)[:through].to_s.singularize}_#{opt[:source].to_s.pluralize}".to_sym]
212
210
  elsif hmt.last.inverse_of.nil?
213
211
  puts "SKIPPING #{hmt.last.name.inspect}"
@@ -298,7 +298,9 @@ if Object.const_defined?('Brick')
298
298
  # # route to go to the :index action for what would be a controller for that table. You can specify any controller
299
299
  # # name and action you wish in order to override this and have that be the default route when none other has been
300
300
  # # specified in routes.rb or elsewhere. (Or just use an empty string in order to disable this behaviour.)
301
- # Brick.default_route_fallback = 'customers' # This defaults to \"customers#index\"
301
+ # This defaults to \"customers#index\", and if there was also a prefix set called \"admin\" then it would instead
302
+ # go to \"admin/customers#index\".
303
+ # Brick.default_route_fallback = 'customers'
302
304
  # Brick.default_route_fallback = 'orders#outstanding' # Example of a non-RESTful route
303
305
  # Brick.default_route_fallback = '' # Omits setting a default route in the absence of any other
304
306
  end
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.81
4
+ version: 1.0.82
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-10-18 00:00:00.000000000 Z
11
+ date: 2022-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord