brick 1.0.85 → 1.0.87
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/brick/compatibility.rb +20 -5
- data/lib/brick/extensions.rb +43 -16
- data/lib/brick/frameworks/rails/engine.rb +22 -9
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +20 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b178117c13e6d4feb053c27334b558285765a68a8bdc00c0a1d7a0a708ab3e70
|
4
|
+
data.tar.gz: b4b90b2cef91df1797d3a6534d6658914000b01542fe244d7560d31922c2125e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7866357360543e3af339aced9e7ff8c1dff803f3f92eebb12926b5cefb4da18415003b729ad5aca3b7771a145035963bd1e49d8a46096bb943a161e4b33ca79
|
7
|
+
data.tar.gz: b2978cf99f81c2ad59b04f656c189763d230542e9eb9d9eb7d3a922c609e79354926357320967f7de53a1a6cc4ec55b61811395138e632cb0f1a96993a31e926
|
data/lib/brick/compatibility.rb
CHANGED
@@ -10,12 +10,27 @@ unless ActiveRecord.respond_to?(:version)
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
module ActionView
|
13
|
+
# ActiveSupport, ActionPack, and ActionView before 4.0 didn't have #version
|
14
|
+
unless ActiveSupport.respond_to?(:version)
|
15
|
+
module ActiveSupport
|
17
16
|
def self.version
|
18
|
-
|
17
|
+
::Gem::Version.new(ActiveSupport::VERSION::STRING)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
if Object.const_defined?('ActionPack')
|
22
|
+
unless ActionPack.respond_to?(:version)
|
23
|
+
module ActionPack
|
24
|
+
def self.version
|
25
|
+
::Gem::Version.new(ActionPack::VERSION::STRING)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
if Object.const_defined?('ActionView') && !ActionView.respond_to?(:version)
|
30
|
+
module ActionView
|
31
|
+
def self.version
|
32
|
+
ActionPack.version
|
33
|
+
end
|
19
34
|
end
|
20
35
|
end
|
21
36
|
end
|
data/lib/brick/extensions.rb
CHANGED
@@ -211,7 +211,14 @@ module ActiveRecord
|
|
211
211
|
this_obj = obj
|
212
212
|
bracket_name.split('.').each do |part|
|
213
213
|
obj_name += ".#{part}"
|
214
|
-
this_obj =
|
214
|
+
this_obj = begin
|
215
|
+
caches.fetch(obj_name) { caches[obj_name] = this_obj&.send(part.to_sym) }
|
216
|
+
rescue
|
217
|
+
clsnm = part.camelize
|
218
|
+
if (possible = this_obj.class.reflect_on_all_associations.select { |a| a.class_name == clsnm || a.klass.base_class.name == clsnm }.first)
|
219
|
+
caches[obj_name] = this_obj&.send(possible.name)
|
220
|
+
end
|
221
|
+
end
|
215
222
|
break if this_obj.nil?
|
216
223
|
end
|
217
224
|
if this_obj.is_a?(ActiveRecord::Base) && (obj_descrip = this_obj.class.brick_descrip(this_obj))
|
@@ -239,7 +246,7 @@ module ActiveRecord
|
|
239
246
|
pk_alias = [pk_alias] unless pk_alias.is_a?(Array)
|
240
247
|
id = []
|
241
248
|
pk_alias.each do |pk_alias_part|
|
242
|
-
if (pk_part = obj.send(pk_alias_part))
|
249
|
+
if (pk_part = obj.respond_to?(pk_alias_part) ? obj.send(pk_alias_part) : nil)
|
243
250
|
id << pk_part
|
244
251
|
end
|
245
252
|
end
|
@@ -608,7 +615,11 @@ module ActiveRecord
|
|
608
615
|
# %%% Need to support {user: :profile}
|
609
616
|
next unless assoc_name.is_a?(Symbol)
|
610
617
|
|
611
|
-
table_alias =
|
618
|
+
table_alias = if (chain = chains[klass = reflect_on_association(assoc_name)&.klass])
|
619
|
+
shift_or_first(chain)
|
620
|
+
else
|
621
|
+
klass.table_name # ActiveRecord < 4.2 can't (yet) use the cool chains thing
|
622
|
+
end
|
612
623
|
_assoc_names[assoc_name] = [table_alias, klass]
|
613
624
|
end
|
614
625
|
end
|
@@ -706,7 +717,7 @@ module ActiveRecord
|
|
706
717
|
join_clause = "LEFT OUTER
|
707
718
|
JOIN (SELECT #{hm_selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', ')}, COUNT(#{'DISTINCT ' if hm.options[:through]}#{count_column
|
708
719
|
}) AS c_t_ FROM #{from_clause || hm_table_name} GROUP BY #{group_bys.join(', ')}) #{tbl_alias}"
|
709
|
-
|
720
|
+
self.joins_values |= ["#{join_clause} ON #{on_clause.join(' AND ')}"] # Same as: joins!(...)
|
710
721
|
end
|
711
722
|
while (n = nix.pop)
|
712
723
|
klass._br_hm_counts.delete(n)
|
@@ -723,7 +734,11 @@ JOIN (SELECT #{hm_selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', '
|
|
723
734
|
s["#{tbl_name}.#{v_parts.last}"] = v.last
|
724
735
|
end
|
725
736
|
end
|
726
|
-
where!
|
737
|
+
if respond_to?(:where!)
|
738
|
+
where!(wheres2)
|
739
|
+
else # AR < 4.0
|
740
|
+
self.where_values << build_where(wheres2)
|
741
|
+
end
|
727
742
|
end
|
728
743
|
# Must parse the order_by and see if there are any symbols which refer to BT associations
|
729
744
|
# or custom columns as they must be expanded to find the corresponding b_r_model__column
|
@@ -747,9 +762,10 @@ JOIN (SELECT #{hm_selects.map { |s| "#{'br_t0.' if from_clause}#{s}" }.join(', '
|
|
747
762
|
selects << v if is_distinct
|
748
763
|
end
|
749
764
|
end
|
750
|
-
order!(*final_order_by)
|
765
|
+
self.order_values |= final_order_by # Same as: order!(*final_order_by)
|
751
766
|
end
|
752
|
-
|
767
|
+
# Don't want to get too carried away just yet
|
768
|
+
self.limit_value = 1000 # Same as: limit!(1000)
|
753
769
|
wheres unless wheres.empty? # Return the specific parameters that we did use
|
754
770
|
end
|
755
771
|
|
@@ -935,8 +951,13 @@ if ActiveSupport::Dependencies.respond_to?(:autoload_module!) # %%% Only works w
|
|
935
951
|
autoloaded_constants << qualified_name unless autoloaded_constants.include?(qualified_name)
|
936
952
|
klass
|
937
953
|
elsif (base_class = ::Brick.config.sti_namespace_prefixes&.fetch("::#{const_name}", nil)&.constantize)
|
938
|
-
|
939
|
-
|
954
|
+
begin
|
955
|
+
# Attempt to find an existing implementation for this subclass
|
956
|
+
base_class.module_parent.const_get(const_name)
|
957
|
+
rescue
|
958
|
+
# Build subclass and place it in the same module as its parent
|
959
|
+
base_class.module_parent.const_set(const_name.to_sym, klass = Class.new(base_class))
|
960
|
+
end
|
940
961
|
else
|
941
962
|
_brick_autoload_module!(*args)
|
942
963
|
end
|
@@ -1509,9 +1530,10 @@ class Object
|
|
1509
1530
|
ordering = params['_brick_order']&.split(',')&.map(&:to_sym) || Object.send(:default_ordering, table_name, pk)
|
1510
1531
|
order_by, _ = model._brick_calculate_ordering(ordering, true) # Don't do the txt part
|
1511
1532
|
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1533
|
+
ar_relation = ActiveRecord.version < Gem::Version.new('4') ? model.preload : model.all
|
1534
|
+
@_brick_params = ar_relation.brick_select(params, (selects = []), order_by,
|
1535
|
+
translations = {},
|
1536
|
+
join_array = ::Brick::JoinArray.new)
|
1515
1537
|
# %%% Add custom HM count columns
|
1516
1538
|
# %%% What happens when the PK is composite?
|
1517
1539
|
counts = model._br_hm_counts.each_with_object([]) do |v, s|
|
@@ -1523,7 +1545,8 @@ class Object
|
|
1523
1545
|
"b_r_#{v.first}.c_t_ AS \"b_r_#{v.first}_ct\""
|
1524
1546
|
end
|
1525
1547
|
end
|
1526
|
-
|
1548
|
+
ar_select = ar_relation.respond_to?(:_select!) ? ar_relation.dup._select!(*selects, *counts) : ar_relation.select(selects + counts)
|
1549
|
+
instance_variable_set("@#{table_name.pluralize}".to_sym, ar_select)
|
1527
1550
|
if namespace && (idx = lookup_context.prefixes.index(table_name))
|
1528
1551
|
lookup_context.prefixes[idx] = "#{namespace.name.underscore}/#{lookup_context.prefixes[idx]}"
|
1529
1552
|
end
|
@@ -1781,6 +1804,8 @@ end.class_exec do
|
|
1781
1804
|
# This is done separately so that during testing it can be called right after a migration
|
1782
1805
|
# in order to make sure everything is good.
|
1783
1806
|
def _brick_reflect_tables
|
1807
|
+
return unless ::Brick.config.mode == :on
|
1808
|
+
|
1784
1809
|
# return if ActiveRecord::Base.connection.current_database == 'postgres'
|
1785
1810
|
|
1786
1811
|
initializer_loaded = false
|
@@ -1854,8 +1879,9 @@ end.class_exec do
|
|
1854
1879
|
::Brick.db_schemas ||= {}
|
1855
1880
|
|
1856
1881
|
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
1857
|
-
if (
|
1858
|
-
|
1882
|
+
if (possible_schemas = ::Brick.config.schema_behavior&.[](:multitenant)&.[](:schema_to_analyse))
|
1883
|
+
possible_schemas = [possible_schemas] unless possible_schemas.is_a?(Array)
|
1884
|
+
if (possible_schema = possible_schemas.find { |ps| ::Brick.db_schemas.key?(ps) })
|
1859
1885
|
::Brick.default_schema = schema = possible_schema
|
1860
1886
|
orig_schema = ActiveRecord::Base.execute_sql('SELECT current_schemas(true)').first['current_schemas'][1..-2].split(',')
|
1861
1887
|
ActiveRecord::Base.execute_sql("SET SEARCH_PATH = ?", schema)
|
@@ -1865,7 +1891,7 @@ end.class_exec do
|
|
1865
1891
|
orig_schema = ActiveRecord::Base.execute_sql('SELECT current_schemas(true)').first['current_schemas'][1..-2].split(',')
|
1866
1892
|
ActiveRecord::Base.execute_sql("SET SEARCH_PATH = ?", schema)
|
1867
1893
|
else
|
1868
|
-
puts "*** In the brick.rb initializer the line \"::Brick.schema_behavior = ...\" refers to
|
1894
|
+
puts "*** In the brick.rb initializer the line \"::Brick.schema_behavior = ...\" refers to schema(s) called #{possible_schemas.map { |s| "\"#{s}\"" }.join(', ')}. No mentioned schema exists. ***"
|
1869
1895
|
end
|
1870
1896
|
end
|
1871
1897
|
end
|
@@ -2028,6 +2054,7 @@ ORDER BY 1, 2, c.internal_column_id, acc.position"
|
|
2028
2054
|
end
|
2029
2055
|
::Brick.is_oracle = true if ActiveRecord::Base.connection.adapter_name == 'OracleEnhanced'
|
2030
2056
|
# ::Brick.default_schema ||= schema ||= 'public' if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
2057
|
+
::Brick.default_schema ||= 'public' if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
2031
2058
|
fk_references&.each do |fk|
|
2032
2059
|
fk = fk.values unless fk.is_a?(Array)
|
2033
2060
|
# Multitenancy makes things a little more general overall, except for non-tenanted tables
|
@@ -103,12 +103,18 @@ module Brick
|
|
103
103
|
unless (model_name = @_brick_model&.name) ||
|
104
104
|
(is_status = ::Brick.config.add_status && args[0..1] == ['status', ['brick_gem']]) ||
|
105
105
|
(is_orphans = ::Brick.config.add_orphans && args[0..1] == ['orphans', ['brick_gem']])
|
106
|
-
if
|
106
|
+
if ActionView.version < ::Gem::Version.new('5.0') # %%% Not sure if this should be perhaps 4.2 instead
|
107
|
+
begin
|
108
|
+
if (possible_template = _brick_find_template(*args, **options))
|
109
|
+
return possible_template
|
110
|
+
end
|
111
|
+
rescue
|
112
|
+
end
|
113
|
+
elsif (possible_template = _brick_find_template(*args, **options))
|
107
114
|
return possible_template
|
108
|
-
else
|
109
|
-
# Used to also have: ActionView.version < ::Gem::Version.new('5.0') &&
|
110
|
-
model_name = (args[1].is_a?(Array) ? set_brick_model(args) : nil)&.name
|
111
115
|
end
|
116
|
+
# Used to also have: ActionView.version < ::Gem::Version.new('5.0') &&
|
117
|
+
model_name = (args[1].is_a?(Array) ? set_brick_model(args) : nil)&.name
|
112
118
|
end
|
113
119
|
|
114
120
|
if @_brick_model
|
@@ -154,7 +160,7 @@ module Brick
|
|
154
160
|
'nil'
|
155
161
|
else
|
156
162
|
# Postgres column names are limited to 63 characters
|
157
|
-
"#{obj_name}.#{"b_r_#{assoc_name}_ct"[0..62]} || 0"
|
163
|
+
"#{obj_name}.#{"b_r_#{assoc_name}_ct"[0..62]}&.to_i || 0"
|
158
164
|
end
|
159
165
|
", #{set_ct}, #{path_keys(hm_assoc, hm_fk_name, obj_name, pk)}"
|
160
166
|
end
|
@@ -919,12 +925,19 @@ erDiagram
|
|
919
925
|
%><%= link_to(\"#\{bt_class} ##\{poly_id}\", send(\"#\{base_class_underscored}_path\".to_sym, poly_id)) if poly_id %><%
|
920
926
|
else
|
921
927
|
# binding.pry if @_brick_bt_descrip[bt.first][bt[1].first.first].nil?
|
922
|
-
|
928
|
+
bt_class = bt[1].first.first
|
929
|
+
descrips = @_brick_bt_descrip[bt.first][bt_class]
|
930
|
+
bt_id_col = if descrips.length == 1
|
931
|
+
[#{obj_name}.class.reflect_on_association(bt.first)&.foreign_key]
|
932
|
+
else
|
933
|
+
descrips.last
|
934
|
+
end
|
935
|
+
bt_txt = bt_class.brick_descrip(
|
923
936
|
# 0..62 because Postgres column names are limited to 63 characters
|
924
|
-
#{obj_name},
|
937
|
+
#{obj_name}, descrips[0..-2].map { |id| #{obj_name}.send(id.last[0..62]) }, bt_id_col
|
925
938
|
)
|
926
939
|
bt_txt ||= \"<span class=\\\"orphan\\\"><< Orphaned ID: #\{val} >></span>\".html_safe if val
|
927
|
-
bt_id = bt_id_col
|
940
|
+
bt_id = bt_id_col&.map { |id_col| #{obj_name}.respond_to?(id_sym = id_col.to_sym) ? #{obj_name}.send(id_sym) : id_col } %>
|
928
941
|
<%= bt_id&.first ? link_to(bt_txt, send(\"#\{bt_class.base_class._brick_index(:singular)}_path\".to_sym, bt_id)) : bt_txt %>
|
929
942
|
<% end
|
930
943
|
elsif (hms_col = hms_cols[col_name])
|
@@ -1183,7 +1196,7 @@ end
|
|
1183
1196
|
s << "<table id=\"#{hm_name}\" class=\"shadow\">
|
1184
1197
|
<tr><th>#{hm[3]}</th></tr>
|
1185
1198
|
<% collection = @#{obj_name}.#{hm_name}
|
1186
|
-
collection = collection.is_a?(ActiveRecord::Associations::CollectionProxy) ? collection.order(#{pk.inspect}) :
|
1199
|
+
collection = collection.is_a?(ActiveRecord::Associations::CollectionProxy) ? collection.order(#{pk.inspect}) : collection.to_a.compact
|
1187
1200
|
if collection.empty? %>
|
1188
1201
|
<tr><td>(none)</td></tr>
|
1189
1202
|
<% else %>
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -137,7 +137,7 @@ module Brick
|
|
137
137
|
|
138
138
|
def set_db_schema(params = nil)
|
139
139
|
schema = (params ? params['_brick_schema'] : ::Brick.default_schema)
|
140
|
-
if schema && ::Brick.db_schemas&.key?(schema)
|
140
|
+
chosen = if schema && ::Brick.db_schemas&.key?(schema)
|
141
141
|
ActiveRecord::Base.execute_sql("SET SEARCH_PATH = ?;", schema)
|
142
142
|
schema
|
143
143
|
elsif ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
@@ -146,6 +146,7 @@ module Brick
|
|
146
146
|
# ::Brick.apartment_multitenant && tbl_parts.first == Apartment.default_schema
|
147
147
|
(orig_schema - ['pg_catalog']).first
|
148
148
|
end
|
149
|
+
chosen == ::Brick.default_schema ? nil : chosen
|
149
150
|
end
|
150
151
|
|
151
152
|
# All tables and views (what Postgres calls "relations" including column and foreign key info)
|
@@ -218,7 +219,7 @@ module Brick
|
|
218
219
|
skip_hms[through] = nil if hms[through] && model.is_brick?
|
219
220
|
# End up with a hash of HMT names pointing to join-table associations
|
220
221
|
model._br_associatives[hmt.first] = hms[through] # || hms["#{(opt = hmt.last.options)[:through].to_s.singularize}_#{opt[:source].to_s.pluralize}".to_sym]
|
221
|
-
elsif hmt.last.inverse_of.nil?
|
222
|
+
elsif hmt.last.inverse_of.nil? && ActiveRecord.version >= ::Gem::Version.new('4.2')
|
222
223
|
puts "SKIPPING #{hmt.last.name.inspect}"
|
223
224
|
# %%% If we don't do this then below associative.name will find that associative is nil
|
224
225
|
skip_hms[hmt.last.name] = nil
|
@@ -540,7 +541,11 @@ In config/initializers/brick.rb appropriate entries would look something like:
|
|
540
541
|
::Brick.is_eager_loading = true
|
541
542
|
if ::ActiveSupport.version < ::Gem::Version.new('6') ||
|
542
543
|
::Rails.configuration.instance_variable_get(:@autoloader) == :classic
|
543
|
-
::
|
544
|
+
if ::ActiveSupport.version < ::Gem::Version.new('4')
|
545
|
+
::Rails.application.eager_load!
|
546
|
+
else
|
547
|
+
::Rails.configuration.eager_load_namespaces.select { |ns| ns < ::Rails::Application }.each(&:eager_load!)
|
548
|
+
end
|
544
549
|
else
|
545
550
|
Zeitwerk::Loader.eager_load_all
|
546
551
|
end
|
@@ -562,7 +567,8 @@ In config/initializers/brick.rb appropriate entries would look something like:
|
|
562
567
|
|
563
568
|
module RouteSet
|
564
569
|
def finalize!
|
565
|
-
|
570
|
+
# %%% Was: ::Rails.application.routes.named_routes.route_defined?(:brick_status_path)
|
571
|
+
unless ::Rails.application.routes.named_routes.names.include?(:brick_status)
|
566
572
|
path_prefix = ::Brick.config.path_prefix
|
567
573
|
existing_controllers = routes.each_with_object({}) do |r, s|
|
568
574
|
c = r.defaults[:controller]
|
@@ -837,13 +843,21 @@ ActiveSupport.on_load(:active_record) do
|
|
837
843
|
end
|
838
844
|
end
|
839
845
|
|
840
|
-
# This only gets added for ActiveRecord < 3.2
|
841
846
|
module Reflection
|
847
|
+
# This only gets added for ActiveRecord < 3.2
|
842
848
|
unless AssociationReflection.instance_methods.include?(:foreign_key)
|
843
849
|
class AssociationReflection < MacroReflection
|
844
850
|
alias foreign_key association_foreign_key
|
845
851
|
end
|
846
852
|
end
|
853
|
+
# And this for ActiveRecord < 4.0
|
854
|
+
unless AssociationReflection.instance_methods.include?(:polymorphic?)
|
855
|
+
class AssociationReflection < MacroReflection
|
856
|
+
def polymorphic?
|
857
|
+
options[:polymorphic]
|
858
|
+
end
|
859
|
+
end
|
860
|
+
end
|
847
861
|
end
|
848
862
|
|
849
863
|
# ActiveRecord 3.1 and 3.2 didn't try to bring in &block for the .extending() convenience thing
|
@@ -1022,6 +1036,7 @@ ActiveSupport.on_load(:active_record) do
|
|
1022
1036
|
delegate :left_outer_joins, to: :all
|
1023
1037
|
end
|
1024
1038
|
class Relation
|
1039
|
+
alias :model :klass unless respond_to?(:model) # To support AR < 4.2
|
1025
1040
|
unless MULTI_VALUE_METHODS.include?(:left_outer_joins)
|
1026
1041
|
_multi_value_methods = MULTI_VALUE_METHODS + [:left_outer_joins]
|
1027
1042
|
send(:remove_const, :MULTI_VALUE_METHODS)
|
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.87
|
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-
|
11
|
+
date: 2022-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: fancy_gets
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|