brick 1.0.163 → 1.0.165
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/frameworks/rails/form_tags.rb +2 -2
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +23 -3
- 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: b468405e9a44d6c7a2a42684eca03309905080c11b2a0b49c3823675308a7176
|
4
|
+
data.tar.gz: cfdb865f37b1b2e9aee8a88685ce48b61e465fcbda924a9089c20b361e1a9fa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53a1d6f0c6bbb01da0ee1288d8c74111322f5a9b15043f61b09270b215322cda34309a5ecdf88cff5cfdea307f8ed1cb92f7ed58bb3aceff1e58bc5e0052a09d
|
7
|
+
data.tar.gz: ce8128a98b0c645bcf8fd1002ec4329ac8b88efc42a112f158a3abcc33373205753b8476d262729ae9b1329d280a129f76f52d467d95c7be99ad3dd48e0b63bb
|
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)
|
@@ -66,8 +66,8 @@ module Brick::Rails::FormTags
|
|
66
66
|
s << "title=\"#{col.comment}\" " if col.respond_to?(:comment) && !col.comment.blank?
|
67
67
|
s << if (bt = bts[col_name])
|
68
68
|
# Allow sorting for any BT except polymorphics
|
69
|
-
"x-order=\"#{bt.first.to_s + '"' unless bt[2]
|
70
|
-
bt[1].map { |bt_pair| bt_pair.first.bt_link(bt.first) }.join(' ')
|
69
|
+
x_order = "x-order=\"#{bt.first.to_s + '"'}" unless bt[2]
|
70
|
+
"#{x_order}>BT #{bt[1].map { |bt_pair| bt_pair.first.bt_link(bt.first) }.join(' ')}"
|
71
71
|
else # Normal column
|
72
72
|
col_name_humanised = klass.human_attribute_name(col_name, { default: col_name })
|
73
73
|
"x-order=\"#{col_name + '"' if true}>#{col_name_humanised}"
|
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 = []
|
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.165
|
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
|