brick 1.0.136 → 1.0.138
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 +13 -6
- data/lib/brick/frameworks/rails/engine.rb +7 -1
- data/lib/brick/frameworks/rails/form_builder.rb +1 -1
- data/lib/brick/frameworks/rails/form_tags.rb +26 -26
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +2 -0
- 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: 2f044e21a6e4c2120a453b6cb3dc404d4d3e3e15034c638d316cbc418bcb996b
|
4
|
+
data.tar.gz: f3360e5e7778bacde155e58bf0683d6b75c74d7dd63d336131e82b0a1865199a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 413c6fe2526752eab0e24998b852e9ae68ef7f56a6488bc14b777e13a4ad281f6c352af465be9e49f05e20fa597e7750d3c706df762f74eb70a18fda5112a319
|
7
|
+
data.tar.gz: cb5040c5333dfa0c0fcbd9d1c04c229e538db1b33fc1526ace987d6da8bd1634e50269e5e05249da6205980ac79c3bad792dd5cc2242115349846365a881bf81
|
data/lib/brick/extensions.rb
CHANGED
@@ -989,7 +989,7 @@ end
|
|
989
989
|
if Object.const_defined?('ActionView')
|
990
990
|
require 'brick/frameworks/rails/form_tags'
|
991
991
|
require 'brick/frameworks/rails/form_builder'
|
992
|
-
module ActionView::Helpers
|
992
|
+
module ::ActionView::Helpers
|
993
993
|
module FormTagHelper
|
994
994
|
include ::Brick::Rails::FormTags
|
995
995
|
end
|
@@ -999,8 +999,8 @@ if Object.const_defined?('ActionView')
|
|
999
999
|
end
|
1000
1000
|
|
1001
1001
|
# FormBuilder#field_id isn't available in Rails < 7.0. This is a rudimentary version with no `index`.
|
1002
|
-
unless ActionView::Helpers::FormBuilder.methods.include?(:field_id)
|
1003
|
-
ActionView::Helpers::FormBuilder.class_exec do
|
1002
|
+
unless ::ActionView::Helpers::FormBuilder.methods.include?(:field_id)
|
1003
|
+
::ActionView::Helpers::FormBuilder.class_exec do
|
1004
1004
|
def field_id(method)
|
1005
1005
|
[object_name, method.to_s].join('_')
|
1006
1006
|
end
|
@@ -1136,6 +1136,12 @@ Module.class_exec do
|
|
1136
1136
|
plural_class_name == 'BrickGem'
|
1137
1137
|
) ||
|
1138
1138
|
model = self.const_get(full_class_name)
|
1139
|
+
# In the very rare case that we've picked up a MODULE which has the same name as what would be the
|
1140
|
+
# resource's MODEL name, just build out an appropriate auto-model on-the-fly. (RailsDevs code has this in PayCustomer.)
|
1141
|
+
# %%% We don't yet display the code for this new model
|
1142
|
+
if model && !model.is_a?(Class)
|
1143
|
+
model, _code = Object.send(:build_model, relations, model.module_parent, model.module_parent.name, singular_class_name)
|
1144
|
+
end
|
1139
1145
|
# if it's a controller and no match or a model doesn't really use the same table name, eager load all models and try to find a model class of the right name.
|
1140
1146
|
Object.send(:build_controller, self, class_name, plural_class_name, model, relations)
|
1141
1147
|
end
|
@@ -1149,7 +1155,7 @@ Module.class_exec do
|
|
1149
1155
|
::Brick.is_oracle ? class_name.upcase : class_name,
|
1150
1156
|
(plural_class_name = class_name.pluralize)].find { |s| Brick.db_schemas&.include?(s) }&.camelize ||
|
1151
1157
|
(::Brick.config.sti_namespace_prefixes&.key?("::#{class_name}::") && class_name) ||
|
1152
|
-
(::Brick.config.table_name_prefixes
|
1158
|
+
(::Brick.config.table_name_prefixes&.values&.include?(class_name) && class_name))
|
1153
1159
|
return self.const_get(schema_name) if !is_tnp_module && self.const_defined?(schema_name)
|
1154
1160
|
|
1155
1161
|
# Build out a module for the schema if it's namespaced
|
@@ -1942,8 +1948,9 @@ class Object
|
|
1942
1948
|
end
|
1943
1949
|
render json: { result: ::Brick.unexclude_column(table_name, col) }
|
1944
1950
|
else
|
1945
|
-
instance_variable_set("@#{singular_table_name}".to_sym,
|
1946
|
-
|
1951
|
+
@_lookup_context.instance_variable_set("@#{singular_table_name}".to_sym,
|
1952
|
+
model.send(:create, send(params_name_sym)))
|
1953
|
+
@_lookup_context.instance_variable_set(:@_brick_model, model)
|
1947
1954
|
index
|
1948
1955
|
render :index
|
1949
1956
|
end
|
@@ -1430,6 +1430,12 @@ end
|
|
1430
1430
|
end
|
1431
1431
|
end
|
1432
1432
|
|
1433
|
+
# %%% Why in the Canvas LMS app does ActionView::Helpers get cleared / reloaded, or otherwise lose access to #brick_grid ???
|
1434
|
+
# Possible fix if somewhere we can implement the #include with:
|
1435
|
+
# (ActiveSupport.const_defined?('Reloader') ? ActiveSupport : ActionDispatch)::Reloader.to_prepare do ... end
|
1436
|
+
# or
|
1437
|
+
# Rails.application.reloader.to_prepare do ... end
|
1438
|
+
self.class.class_exec { include ::Brick::Rails::FormTags } unless respond_to?(:brick_grid)
|
1433
1439
|
# Write out the mega-grid
|
1434
1440
|
brick_grid(@#{table_name}, @_brick_bt_descrip, @_brick_sequence, @_brick_incl, @_brick_excl,
|
1435
1441
|
cols, poly_cols, bts, #{hms_keys.inspect}, {#{hms_columns.join(', ')}}) %>
|
@@ -1470,7 +1476,7 @@ end
|
|
1470
1476
|
kls = Object.const_get(::Brick.relations.fetch(r[0], nil)&.fetch(:class_name, nil))
|
1471
1477
|
rescue
|
1472
1478
|
end
|
1473
|
-
kls ? link_to(r[0], send(\"#\{kls._brick_index}_path\".to_sym)) : r[0] %></td>
|
1479
|
+
kls.is_a?(Class) ? link_to(r[0], send(\"#\{kls._brick_index}_path\".to_sym)) : r[0] %></td>
|
1474
1480
|
<td<%= if r[1]
|
1475
1481
|
' class=\"orphan\"' unless ::Brick.relations.key?(r[1])
|
1476
1482
|
else
|
@@ -36,9 +36,9 @@ module Brick::Rails::FormTags
|
|
36
36
|
end
|
37
37
|
sequence.reject! { |nm| exclusions.include?(nm) } if exclusions
|
38
38
|
out << sequence.each_with_object(+'') do |col_name, s|
|
39
|
+
s << '<th '
|
39
40
|
if (col = cols[col_name]).is_a?(ActiveRecord::ConnectionAdapters::Column)
|
40
|
-
s <<
|
41
|
-
s << "title=\"#{col.comment}\"" if col.respond_to?(:comment) && !col.comment.blank?
|
41
|
+
s << "title=\"#{col.comment}\" " if col.respond_to?(:comment) && !col.comment.blank?
|
42
42
|
s << if (bt = bts[col_name])
|
43
43
|
# Allow sorting for any BT except polymorphics
|
44
44
|
"x-order=\"#{bt.first.to_s + '"' unless bt[2]}>BT " +
|
@@ -49,18 +49,18 @@ module Brick::Rails::FormTags
|
|
49
49
|
elsif col # HM column
|
50
50
|
options = {}
|
51
51
|
options[col[1].inheritance_column] = col[1].name unless col[1] == col[1].base_class
|
52
|
-
s << "
|
52
|
+
s << "x-order=\"#{col_name + '"' if true}>#{col[2]} "
|
53
53
|
s << (col.first ? "#{col[3]}" : "#{link_to(col[3], send("#{col[1]._brick_index}_path", options))}")
|
54
54
|
elsif cust_cols.key?(col_name) # Custom column
|
55
|
-
s << "
|
55
|
+
s << "x-order=\"#{col_name}\">#{col_name}"
|
56
56
|
elsif col_name.is_a?(Symbol) && (hot = bts[col_name]) # has_one :through
|
57
|
-
s << "
|
57
|
+
s << "x-order=\"#{hot.first.to_s}\">HOT " +
|
58
58
|
hot[1].map { |hot_pair| hot_pair.first.bt_link(col_name) }.join(' ')
|
59
59
|
elsif (bt = composite_bt_names[col_name])
|
60
|
-
s << "
|
60
|
+
s << "x-order=\"#{bt.first.to_s + '"' unless bt[2]}>BT comp " +
|
61
61
|
bt[1].map { |bt_pair| bt_pair.first.bt_link(bt.first) }.join(' ')
|
62
62
|
else # Bad column name!
|
63
|
-
s << "
|
63
|
+
s << "title=\"<< Unknown column >>\">#{col_name}"
|
64
64
|
end
|
65
65
|
s << '</th>'
|
66
66
|
end
|
@@ -93,18 +93,20 @@ module Brick::Rails::FormTags
|
|
93
93
|
end
|
94
94
|
else # BT or HOT
|
95
95
|
bt_class = bt[1].first.first
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
96
|
+
if bt_descrip
|
97
|
+
descrips = bt_descrip[bt.first][bt_class]
|
98
|
+
bt_id_col = if descrips.nil?
|
99
|
+
puts "Caught it in the act for obj / #{col_name}!"
|
100
|
+
elsif descrips.length == 1
|
101
|
+
[obj.class.reflect_on_association(bt.first)&.foreign_key]
|
102
|
+
else
|
103
|
+
descrips.last
|
104
|
+
end
|
105
|
+
end
|
106
|
+
br_descrip_args = [obj]
|
107
|
+
# 0..62 because Postgres column names are limited to 63 characters
|
108
|
+
br_descrip_args += [descrips[0..-2].map { |id| obj.send(id.last[0..62]) }, bt_id_col] if descrips
|
109
|
+
bt_txt = bt_class.brick_descrip(*br_descrip_args)
|
108
110
|
bt_txt = ::Brick::Rails.display_binary(bt_txt).html_safe if bt_txt&.encoding&.name == 'ASCII-8BIT'
|
109
111
|
bt_txt ||= "<span class=\"orphan\"><< Orphaned ID: #{val} >></span>" if val
|
110
112
|
bt_id = bt_id_col&.map { |id_col| obj.respond_to?(id_sym = id_col.to_sym) ? obj.send(id_sym) : id_col }
|
@@ -128,13 +130,11 @@ module Brick::Rails::FormTags
|
|
128
130
|
end
|
129
131
|
out << link_to(ho_txt, send("#{hm_klass.base_class._brick_index(:singular)}_path".to_sym, ho_id))
|
130
132
|
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
send("#{hm_klass._brick_index}_path".to_sym, predicates))}\n"
|
137
|
-
end
|
133
|
+
elsif obj.respond_to?(ct_col = hms_col[1].to_sym) && (ct = obj.send(ct_col)&.to_i)&.positive?
|
134
|
+
predicates = hms_col[2].each_with_object({}) { |v, s| s[v.first] = v.last.is_a?(String) ? v.last : obj.send(v.last) }
|
135
|
+
predicates.each { |k, v| predicates[k] = obj.class.name if v == '[sti_type]' }
|
136
|
+
out << "#{link_to("#{ct || 'View'} #{hms_col.first}",
|
137
|
+
send("#{hm_klass._brick_index}_path".to_sym, predicates))}\n"
|
138
138
|
end
|
139
139
|
end
|
140
140
|
elsif (col = cols[col_name]).is_a?(ActiveRecord::ConnectionAdapters::Column)
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -163,6 +163,8 @@ module Brick
|
|
163
163
|
|
164
164
|
# All tables and views (what Postgres calls "relations" including column and foreign key info)
|
165
165
|
def relations
|
166
|
+
return {} if ::ActiveRecord::Base.connection_handler.connection_pool_list.blank?
|
167
|
+
|
166
168
|
# Key our list of relations for this connection off of the connection pool's object_id
|
167
169
|
(@relations ||= {})[ActiveRecord::Base.connection_pool.object_id] ||= Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = {} } }
|
168
170
|
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.
|
4
|
+
version: 1.0.138
|
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-
|
11
|
+
date: 2023-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|