brick 1.0.180 → 1.0.182
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/brick/compatibility.rb +19 -3
- data/lib/brick/extensions.rb +21 -12
- data/lib/brick/frameworks/rails/engine.rb +9 -8
- data/lib/brick/frameworks/rails/form_tags.rb +4 -4
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +24 -19
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 390cb3f8a466f1d94c0e8e7472017753fb09f8c9909a71134545e25b47edfb21
|
|
4
|
+
data.tar.gz: 9398ee17aa8a5b8741adf784ebde9421f6419f93a421ec0ba5893f028b192383
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75c2d9f206d58f5296862fcdec776b3a5daa82e2c7405ff3fa46bf386e61cfac39ddf9cf55d7ab3eb54ddf23434c5086fd99e6d9eca0543ed63d9946892ea140
|
|
7
|
+
data.tar.gz: 1818e986519622fd6c51c25e0153e003a476c7e823f14ff4cc9aabdf4cfb1adae7fe8f67ff1e9ca1a181694e028aa3b0c985afad8ab88b5c1d839be3aba70ed0
|
data/lib/brick/compatibility.rb
CHANGED
|
@@ -115,14 +115,30 @@ if Object.const_defined?('ActionPack') && !ActionPack.respond_to?(:version)
|
|
|
115
115
|
end
|
|
116
116
|
end
|
|
117
117
|
end
|
|
118
|
-
if Bundler.locked_gems&.dependencies.key?('action_view')
|
|
118
|
+
if Object.const_defined?('Bundler') && Bundler.locked_gems&.dependencies.key?('action_view')
|
|
119
119
|
require 'action_view' # Needed for Rails <= 4.0
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
module ::ActionView
|
|
121
|
+
if Object.const_defined?('ActionView') && !ActionView.respond_to?(:version)
|
|
122
122
|
def self.version
|
|
123
123
|
ActionPack.version
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
|
+
if self.version < ::Gem::Version.new('5.2')
|
|
127
|
+
module Helpers
|
|
128
|
+
module TextHelper
|
|
129
|
+
# Older versions of #pluralize lack the all-important .to_s
|
|
130
|
+
def pluralize(count, singular, plural_arg = nil, plural: plural_arg, locale: I18n.locale)
|
|
131
|
+
word = if (count == 1 || count.to_s =~ /^1(\.0+)?$/)
|
|
132
|
+
singular
|
|
133
|
+
else
|
|
134
|
+
plural || singular.pluralize(locale)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
"#{count || 0} #{word}"
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
126
142
|
end
|
|
127
143
|
end
|
|
128
144
|
|
data/lib/brick/extensions.rb
CHANGED
|
@@ -1545,8 +1545,7 @@ class Object
|
|
|
1545
1545
|
is_sti = true
|
|
1546
1546
|
else
|
|
1547
1547
|
# Class for auto-generated models to inherit from
|
|
1548
|
-
base_model = (::Brick.config.models_inherit_from ||= (
|
|
1549
|
-
begin
|
|
1548
|
+
base_model = (::Brick.config.models_inherit_from ||= (begin
|
|
1550
1549
|
::ApplicationRecord
|
|
1551
1550
|
rescue StandardError => ex
|
|
1552
1551
|
::ActiveRecord::Base
|
|
@@ -1610,9 +1609,14 @@ class Object
|
|
|
1610
1609
|
if has_pk
|
|
1611
1610
|
code << " # Primary key: #{_brick_primary_key.join(', ')}\n" unless _brick_primary_key == ['id']
|
|
1612
1611
|
elsif our_pks&.present?
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1612
|
+
pk_mutator = if respond_to?(:'primary_keys=')
|
|
1613
|
+
'primary_keys=' # Using the composite_primary_keys gem
|
|
1614
|
+
elsif ActiveRecord.version >= Gem::Version.new('7.1')
|
|
1615
|
+
'primary_key=' # Rails 7.1+?
|
|
1616
|
+
end
|
|
1617
|
+
if our_pks.length > 1 && pk_mutator
|
|
1618
|
+
new_model_class.send(pk_mutator, our_pks)
|
|
1619
|
+
code << " self.#{pk_mutator[0..-2]} = #{our_pks.map(&:to_sym).inspect}\n"
|
|
1616
1620
|
else
|
|
1617
1621
|
new_model_class.primary_key = (pk_sym = our_pks.first.to_sym)
|
|
1618
1622
|
code << " self.primary_key = #{pk_sym.inspect}\n"
|
|
@@ -1790,14 +1794,19 @@ class Object
|
|
|
1790
1794
|
singular_table_parts.shift
|
|
1791
1795
|
end
|
|
1792
1796
|
options[:class_name] = "::#{assoc[:primary_class]&.name || singular_table_parts.map(&:camelize).join('::')}" if need_class_name
|
|
1793
|
-
# Work around a bug in CPK where self-referencing belongs_to associations double up their foreign keys
|
|
1794
1797
|
if need_fk # Funky foreign key?
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1798
|
+
options_fk_key = :foreign_key
|
|
1799
|
+
if assoc[:fk].is_a?(Array)
|
|
1800
|
+
# #uniq works around a bug in CPK where self-referencing belongs_to associations double up their foreign keys
|
|
1801
|
+
if (assoc_fk = assoc[:fk].uniq).length > 1
|
|
1802
|
+
options_fk_key = :query_constraints if ActiveRecord.version >= ::Gem::Version.new('7.1')
|
|
1803
|
+
options[options_fk_key] = assoc_fk
|
|
1804
|
+
else
|
|
1805
|
+
options[options_fk_key] = assoc_fk.first
|
|
1806
|
+
end
|
|
1807
|
+
else
|
|
1808
|
+
options[options_fk_key] = assoc[:fk].to_sym
|
|
1809
|
+
end
|
|
1801
1810
|
end
|
|
1802
1811
|
if inverse_assoc_name && (need_class_name || need_fk || need_inverse_of) &&
|
|
1803
1812
|
(klass = options[:class_name]&.constantize) && (ian = inverse_assoc_name.tr('.', '_').to_sym) &&
|
|
@@ -1404,12 +1404,6 @@ end
|
|
|
1404
1404
|
#{erd_markup}
|
|
1405
1405
|
|
|
1406
1406
|
<%= # Consider getting the name from the association -- hm.first.name -- if a more \"friendly\" alias should be used for a screwy table name
|
|
1407
|
-
cols = {#{hms_keys = []
|
|
1408
|
-
hms_headers.map do |hm|
|
|
1409
|
-
hms_keys << (assoc_name = (assoc = hm.first).name.to_s)
|
|
1410
|
-
"#{assoc_name.inspect} => [#{(assoc.options[:through] && !assoc.through_reflection).inspect}, #{assoc.klass.name}, #{hm[1].inspect}, #{hm[2].inspect}]"
|
|
1411
|
-
end.join(', ')}}
|
|
1412
|
-
|
|
1413
1407
|
# If the resource is missing, has the user simply created an inappropriately pluralised name for a table?
|
|
1414
1408
|
@#{table_name} ||= if (dym_list = instance_variables.reject do |entry|
|
|
1415
1409
|
entry.to_s.start_with?('@_') ||
|
|
@@ -1429,6 +1423,13 @@ end
|
|
|
1429
1423
|
end
|
|
1430
1424
|
end
|
|
1431
1425
|
|
|
1426
|
+
# Starts as being just has_many columns, and will be augmented later with all the other columns
|
|
1427
|
+
cols = {#{hms_keys = []
|
|
1428
|
+
hms_headers.map do |hm|
|
|
1429
|
+
hms_keys << (assoc_name = (assoc = hm.first).name.to_s)
|
|
1430
|
+
"#{assoc_name.inspect} => [#{(assoc.options[:through] && !assoc.through_reflection).inspect}, #{assoc.klass.name}, #{hm[1].inspect}, #{hm[2].inspect}]"
|
|
1431
|
+
end.join(', ')}}
|
|
1432
|
+
|
|
1432
1433
|
# %%% Why in the Canvas LMS app does ActionView::Helpers get cleared / reloaded, or otherwise lose access to #brick_grid ???
|
|
1433
1434
|
# Possible fix if somewhere we can implement the #include with:
|
|
1434
1435
|
# (ActiveSupport.const_defined?('Reloader') ? ActiveSupport : ActionDispatch)::Reloader.to_prepare do ... end
|
|
@@ -1436,8 +1437,8 @@ end
|
|
|
1436
1437
|
# Rails.application.reloader.to_prepare do ... end
|
|
1437
1438
|
self.class.class_exec { include ::Brick::Rails::FormTags } unless respond_to?(:brick_grid)
|
|
1438
1439
|
# Write out the mega-grid
|
|
1439
|
-
brick_grid(@#{table_name}, @
|
|
1440
|
-
cols, poly_cols, bts, #{hms_keys.inspect}, {#{hms_columns.join(', ')}}) %>
|
|
1440
|
+
brick_grid(@#{table_name}, @_brick_sequence, @_brick_incl, @_brick_excl,
|
|
1441
|
+
cols, bt_descrip: @_brick_bt_descrip, poly_cols: poly_cols, bts: bts, hms_keys: #{hms_keys.inspect}, hms_cols: {#{hms_columns.join(', ')}}) %>
|
|
1441
1442
|
|
|
1442
1443
|
#{"<hr><%= link_to(\"New #{new_path_name = "new_#{path_obj_name}_path"
|
|
1443
1444
|
obj_name}\", #{new_path_name}, { class: '__brick' }) if respond_to?(:#{new_path_name}) %>" unless @_brick_model.is_view?}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Brick::Rails::FormTags
|
|
2
2
|
# Our super speedy grid
|
|
3
|
-
def brick_grid(relation = nil,
|
|
4
|
-
cols = {}, poly_cols
|
|
3
|
+
def brick_grid(relation = nil, sequence = nil, inclusions = nil, exclusions = nil,
|
|
4
|
+
cols = {}, bt_descrip: nil, poly_cols: nil, bts: {}, hms_keys: [], hms_cols: {},
|
|
5
5
|
show_header: nil, show_row_count: nil, show_erd_button: nil, show_new_button: nil, show_avo_button: nil, show_aa_button: nil)
|
|
6
6
|
# When a relation is not provided, first see if one exists which matches the controller name
|
|
7
7
|
unless (relation ||= instance_variable_get("@#{controller_name}".to_sym))
|
|
@@ -158,7 +158,7 @@ module Brick::Rails::FormTags
|
|
|
158
158
|
pk.map { |pk_part| obj.send(pk_part.to_sym) }), { class: 'big-arrow' })}</td>\n" if pk.present?
|
|
159
159
|
sequence.each_with_index do |col_name, idx|
|
|
160
160
|
val = obj.attributes[col_name]
|
|
161
|
-
bt = bts[col_name]
|
|
161
|
+
bt = bts[col_name] || composite_bt_names[col_name]
|
|
162
162
|
out << '<td'
|
|
163
163
|
(classes ||= []) << 'col-sticky' if idx < nfc
|
|
164
164
|
(classes ||= []) << 'dimmed' unless cols.key?(col_name) || (cust_col = cust_cols[col_name]) ||
|
|
@@ -166,7 +166,7 @@ module Brick::Rails::FormTags
|
|
|
166
166
|
(classes ||= []) << 'right' if val.is_a?(Numeric) && !bt
|
|
167
167
|
out << " class=\"#{classes.join(' ')}\"" if classes&.present?
|
|
168
168
|
out << '>'
|
|
169
|
-
if
|
|
169
|
+
if bt
|
|
170
170
|
if bt[2] && obj.respond_to?(poly_id_col = "#{bt.first}_id") # Polymorphic?
|
|
171
171
|
if (poly_id = obj.send(poly_id_col))
|
|
172
172
|
bt_class = obj.send(klass.brick_foreign_type(bt.first))
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
|
@@ -203,23 +203,25 @@ module Brick
|
|
|
203
203
|
end
|
|
204
204
|
|
|
205
205
|
model_cols = model.columns_hash
|
|
206
|
-
pk_type = if (mpk = model.primary_key).is_a?(Array)
|
|
207
|
-
# Composite keys should really use: model.primary_key.map { |pk_part| model_cols[pk_part].type }
|
|
208
|
-
model_cols[mpk.first].type
|
|
209
|
-
else
|
|
210
|
-
mpk && model_cols[mpk].type
|
|
211
|
-
end
|
|
212
206
|
bts, hms = model.reflect_on_all_associations.each_with_object([{}, {}]) do |a, s|
|
|
213
|
-
# %%% The time will come when we will support type checking of composite foreign keys!
|
|
214
|
-
# binding.pry if a.foreign_key.is_a?(Array)
|
|
215
207
|
if a.belongs_to? && !a.polymorphic? && ::Brick.config.polymorphics.fetch(full_assoc_name = "#{model.table_name}.#{a.name}", nil)
|
|
216
208
|
puts "Based on inclusion in ::Brick.polymorphics, marking association #{full_assoc_name} as being polymorphic."
|
|
217
209
|
a.options[:polymorphic] = true
|
|
218
210
|
end
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
211
|
+
if !a.polymorphic? && (a.belongs_to? || (through = a.options[:through])) &&
|
|
212
|
+
!(a.klass && ::Brick.config.exclude_tables.exclude?(a.klass.table_name) &&
|
|
213
|
+
(!a.belongs_to? ||
|
|
214
|
+
((fk_type = a.foreign_key.is_a?(Array) ? a.foreign_key.map { |fk_part| model_cols[fk_part.to_s].type } : model_cols[a.foreign_key.to_s].type) &&
|
|
215
|
+
(primary_cols = a.klass.columns_hash) &&
|
|
216
|
+
(pk_type = a.klass.primary_key.is_a?(Array) ? a.klass.primary_key.map { |pk_part| primary_cols[pk_part.to_s].type } : primary_cols[a.klass.primary_key].type) &&
|
|
217
|
+
(same_type = (pk_type == fk_type))
|
|
218
|
+
)
|
|
219
|
+
)
|
|
220
|
+
)
|
|
221
|
+
# unless a.polymorphic? || (!a.belongs_to? && (through = a.options[:through])) ||
|
|
222
|
+
# (a.klass && ::Brick.config.exclude_tables.exclude?(a.klass.table_name) &&
|
|
223
|
+
# (!a.belongs_to? || (same_type = (fk_type = model_cols[a.foreign_key.to_s]&.type) == pk_type))
|
|
224
|
+
# )
|
|
223
225
|
if same_type == false # We really do want to test specifically for false here, and not nil!
|
|
224
226
|
puts "WARNING:
|
|
225
227
|
Foreign key column #{a.klass.table_name}.#{a.foreign_key} is #{fk_type}, but the primary key it relates to, #{a.active_record.table_name}.#{a.active_record.primary_key}, is #{pk_type}.
|
|
@@ -280,7 +282,8 @@ module Brick
|
|
|
280
282
|
next
|
|
281
283
|
end
|
|
282
284
|
else
|
|
283
|
-
|
|
285
|
+
this_fks = this_fk.is_a?(Array) ? this_fk : [this_fk.to_s]
|
|
286
|
+
if !a.options.key?(:as) && (this_fks - a.klass.column_names).length.positive?
|
|
284
287
|
options = ", #{a.options.map { |k, v| "#{k.inspect} => #{v.inspect}" }.join(', ')}" if a.options.present?
|
|
285
288
|
puts "WARNING: Model #{model.name} has this association:
|
|
286
289
|
has_many :#{a.name}#{options}
|
|
@@ -1544,7 +1547,7 @@ ActiveSupport.on_load(:active_record) do
|
|
|
1544
1547
|
else
|
|
1545
1548
|
{}
|
|
1546
1549
|
end
|
|
1547
|
-
_original_initialize(klass, **kwargs)
|
|
1550
|
+
_original_initialize(klass, *args, **kwargs)
|
|
1548
1551
|
end
|
|
1549
1552
|
end
|
|
1550
1553
|
end
|
|
@@ -2036,11 +2039,13 @@ if ActiveRecord.version < ::Gem::Version.new('6.0') && ruby_version >= ::Gem::Ve
|
|
|
2036
2039
|
end
|
|
2037
2040
|
|
|
2038
2041
|
# AR >= 5.0 on Ruby >= 3.0
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2042
|
+
if ActiveRecord.version >= ::Gem::Version.new('5.0')
|
|
2043
|
+
::ActiveRecord::Type::AdapterSpecificRegistry.class_exec do
|
|
2044
|
+
alias :_brick_add_modifier :add_modifier
|
|
2045
|
+
def add_modifier(*args, **kwargs)
|
|
2046
|
+
kwargs.merge!(args.pop) if args.length > 2 && args.last.is_a?(Hash)
|
|
2047
|
+
_brick_add_modifier(*args, **kwargs)
|
|
2048
|
+
end
|
|
2044
2049
|
end
|
|
2045
2050
|
end
|
|
2046
2051
|
|
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.182
|
|
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-10-
|
|
11
|
+
date: 2023-10-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -164,6 +164,20 @@ dependencies:
|
|
|
164
164
|
- - "~>"
|
|
165
165
|
- !ruby/object:Gem::Version
|
|
166
166
|
version: 1.42.0
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: rswag-ui
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - ">="
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '0'
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - ">="
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '0'
|
|
167
181
|
- !ruby/object:Gem::Dependency
|
|
168
182
|
name: mysql2
|
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|