brick 1.0.162 → 1.0.164
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +44 -0
- data/lib/brick/frameworks/rails/engine.rb +1 -0
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +27 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 954b8c68167f01f4c6c05b2a9e7f0956122001e72523c5c2222b7da97370f11c
|
4
|
+
data.tar.gz: 944590e83681412d1fe30133e3ce6407e7eda8636c4c1eb5d5baed12423d190e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d12b53be830841e54f14ac6e860b0cc38a7ad830a8e83bb9ac4c35023f4b98d12b2e37efe9964b10c94bded717b4cedb8f32b51ce64d8d71020a654ec1357b4
|
7
|
+
data.tar.gz: a2474cf50a27f0af680bff905cfe58d27dc3b8e068babbf0d49d1238dde7b11ae33dd8b8a9601fec1e7e26cc6e12f116cc8bfe276705655c1f339b6d92b3af86
|
data/lib/brick/extensions.rb
CHANGED
@@ -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)
|
data/lib/brick/version_number.rb
CHANGED
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, :
|
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
|
-
|
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 = []
|
@@ -844,10 +864,10 @@ In config/initializers/brick.rb appropriate entries would look something like:
|
|
844
864
|
schema_prefix = "#{schema_name}."
|
845
865
|
end
|
846
866
|
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
867
|
+
resource_name = v.fetch(:resource, nil)
|
868
|
+
next if !resource_name ||
|
869
|
+
existing_controllers.key?(
|
870
|
+
controller_prefix + (resource_name = "#{schema_prefix&.tr('.', '/')}#{resource_name}".pluralize)
|
851
871
|
)
|
852
872
|
|
853
873
|
object_name = k.split('.').last # Take off any first schema part
|
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.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-
|
11
|
+
date: 2023-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|