brick 1.0.163 → 1.0.164

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: 374d9798fdc763aaa0db8f80242d9e96723983180085ac0993bd5bf0d6a5eee3
4
- data.tar.gz: 526d1c7f9340775ff44a6fd672c22b3f65e7409e2f366698a33b89c6e6f7c9e2
3
+ metadata.gz: 954b8c68167f01f4c6c05b2a9e7f0956122001e72523c5c2222b7da97370f11c
4
+ data.tar.gz: 944590e83681412d1fe30133e3ce6407e7eda8636c4c1eb5d5baed12423d190e
5
5
  SHA512:
6
- metadata.gz: 775a1789c9193d9f3884e8cec1b036e3638863155c799c0d50fd6b49cb777161d1db3bc64b65504cb8d926db261f636dd0f8cdd9a7d687efadb5a8bc4a383b3b
7
- data.tar.gz: 857bf99caa4faac87af448196679a098e2461e7f1ae46ff37c6653298f91ab5cce777e1caebd0771836b907b691a467bf51da6e90bbad060b7ccf4259c24eee9
6
+ metadata.gz: 2d12b53be830841e54f14ac6e860b0cc38a7ad830a8e83bb9ac4c35023f4b98d12b2e37efe9964b10c94bded717b4cedb8f32b51ce64d8d71020a654ec1357b4
7
+ data.tar.gz: a2474cf50a27f0af680bff905cfe58d27dc3b8e068babbf0d49d1238dde7b11ae33dd8b8a9601fec1e7e26cc6e12f116cc8bfe276705655c1f339b6d92b3af86
@@ -481,6 +481,10 @@ module ActiveRecord
481
481
  relation.select(selects)
482
482
  end
483
483
 
484
+ def self.brick_where(*args)
485
+ (relation = all).brick_where(*args)
486
+ end
487
+
484
488
  private
485
489
 
486
490
  def self._brick_get_fks
@@ -989,6 +993,46 @@ JOIN (SELECT #{hm_selects.map { |s| _br_quoted_name("#{'br_t0.' if from_clause}#
989
993
  [self.select(selects), descrip_cols]
990
994
  end
991
995
 
996
+ # Smart Brick #where that automatically adds the inner JOINs when you have a query like:
997
+ # Customer.brick_where('orders.order_details.order_date' => '2005-1-1', 'orders.employee.first_name' => 'Nancy')
998
+ # Way to make it a more intrinsic part of ActiveRecord
999
+ # alias _brick_where! where!
1000
+ # def where!(opts, *rest)
1001
+ def brick_where(opts)
1002
+ if opts.is_a?(Hash)
1003
+ # && joins_values.empty? # Make sure we don't step on any toes if they've already specified JOIN things
1004
+ ja = nil
1005
+ opts.each do |k, v|
1006
+ if k.is_a?(String) && (ref_parts = k.split('.')).length > 1
1007
+ # JOIN in all the same ways as the pathing describes
1008
+ linkage = (ja ||= ::Brick::JoinArray.new)
1009
+ ref_parts[0..-3].each do |prefix_part|
1010
+ linkage = linkage[prefix_part.to_sym]
1011
+ end
1012
+ linkage[ref_parts[-2].to_sym] = nil
1013
+ end
1014
+ end
1015
+ if ja&.present?
1016
+ if ActiveRecord.version < Gem::Version.new('4.2')
1017
+ self.joins_values += ja # Same as: joins!(ja)
1018
+ else
1019
+ self.joins!(ja)
1020
+ end
1021
+ (ast_tree = self.dup).arel.ast # Walk the AST tree so we can rewrite the prefixes accordingly
1022
+ conditions = opts.each_with_object({}) do |v, s|
1023
+ if (ref_parts = v.first.split('.')).length > 1 &&
1024
+ (tbl = ast_tree.brick_links[ref_parts[0..-2].join('.')])
1025
+ s["#{tbl}.#{ref_parts.last}"] = v.last
1026
+ else
1027
+ s[v.first] = v.last
1028
+ end
1029
+ end
1030
+ end
1031
+ end
1032
+ # If you want it to be more intrinsic with ActiveRecord, do this instead: super(conditions, *rest)
1033
+ self.where!(conditions)
1034
+ end
1035
+
992
1036
  # Accommodate when a relation gets queried for a model, and in that model it has an #after_initialize block
993
1037
  # which references attributes that were not originally included as part of the select_values.
994
1038
  def brick_(method, *args, brick_orig_relation: nil, **kwargs, &block)
@@ -2002,6 +2002,7 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
2002
2002
  send(:root, action)
2003
2003
  end
2004
2004
  end
2005
+ ::Brick.established_drf = "/#{::Brick.config.path_prefix}#{'#index' unless route.index('#')}"
2005
2006
  end
2006
2007
  end
2007
2008
 
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 163
8
+ TINY = 164
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
@@ -107,7 +107,8 @@ module Brick
107
107
  end
108
108
 
109
109
  attr_accessor :default_schema, :db_schemas, :test_schema,
110
- :routes_done, :is_oracle, :is_eager_loading, :auto_models, :initializer_loaded
110
+ :routes_done, :established_drf,
111
+ :is_oracle, :is_eager_loading, :auto_models, :initializer_loaded
111
112
  ::Brick.auto_models = []
112
113
 
113
114
  def set_db_schema(params = nil)
@@ -808,8 +809,27 @@ In config/initializers/brick.rb appropriate entries would look something like:
808
809
  routeset_to_use = ::Rails.application.routes
809
810
  path_prefix = ::Brick.config.path_prefix
810
811
  existing_controllers = routeset_to_use.routes.each_with_object({}) do |r, s|
811
- c = r.defaults[:controller]
812
- s[c] = nil if c
812
+ if r.verb == 'GET' && (c = r.defaults[:controller])
813
+ path = r.path.ast.to_s
814
+ path = path[0..((path.index('(') || 0) - 1)]
815
+ # Skip adding this if it's the default_route_fallback set from the initializers/brick.rb file
816
+ next if "#{path}##{r.defaults[:action]}" == ::Brick.established_drf
817
+
818
+ # next unless [:index, :show, :new, :edit].incude?(a = r.defaults[:action])
819
+
820
+ # c_parts = c.split('/')
821
+ # while c_parts.length > 0
822
+ # c_dotted = c_parts.join('.')
823
+ # if (relation = ::Brick.relations[c_dotted]) # Does it match up with an existing Brick table / resource name?
824
+ # puts path
825
+ # puts " #{c_dotted}##{r.defaults[:action]}"
826
+ # s[c_dotted.tr('.', '/')] = nil
827
+ # break
828
+ # end
829
+ # c_parts.shift
830
+ # end
831
+ s[c] = nil
832
+ end
813
833
  end
814
834
 
815
835
  tables = []
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.163
4
+ version: 1.0.164
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorin Thwaits
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-14 00:00:00.000000000 Z
11
+ date: 2023-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord