brick 1.0.20 → 1.0.21
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/config.rb +14 -0
- data/lib/brick/extensions.rb +3 -1
- data/lib/brick/frameworks/rails/engine.rb +10 -3
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +8 -2
- data/lib/generators/brick/install_generator.rb +6 -1
- 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: 0ad289d9f4db9ef6ce9edcfb8948926d4a61910294291272ccf2b342fa2f5051
|
4
|
+
data.tar.gz: 9030f9ccf39d7f0a9a0ff9413e4f24ee7a46beaf3aba056e9875fc5c29551419
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed6f08eabba91cb304141a0c84884cfbeaae0087094b1fe1ff4a80195aee44dbb697c385ab9d7afaac2e337f9008bc7bef059be98f95264fec34a2288beaff6b
|
7
|
+
data.tar.gz: 5ebbb793d23634232a529b3d39224e1e4deaa010cf8bf2841effe20a9e3b4d7079fb7163e6c2f90feeed8526c4a1314f319bad47d1c8a6079bf54ca92f0e6224
|
data/lib/brick/config.rb
CHANGED
@@ -74,6 +74,20 @@ module Brick
|
|
74
74
|
@mutex.synchronize { @exclude_hms = skips }
|
75
75
|
end
|
76
76
|
|
77
|
+
# Skip showing counts for these specific has_many associations when building auto-generated #index views
|
78
|
+
def skip_index_hms
|
79
|
+
@mutex.synchronize { @skip_index_hms || {} }
|
80
|
+
end
|
81
|
+
|
82
|
+
def skip_index_hms=(skips)
|
83
|
+
@mutex.synchronize do
|
84
|
+
@skip_index_hms ||= skips.each_with_object({}) do |v, s|
|
85
|
+
class_name, assoc_name = v.split('.')
|
86
|
+
(s[class_name] ||= {})[assoc_name.to_sym] = nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
77
91
|
# Associations to treat as a has_one
|
78
92
|
def has_ones
|
79
93
|
@mutex.synchronize { @has_ones }
|
data/lib/brick/extensions.rb
CHANGED
@@ -304,7 +304,10 @@ module ActiveRecord
|
|
304
304
|
# join_array[bt.first] = nil # Store this relation name in our special collection for .joins()
|
305
305
|
bt_descrip[bt.first] = [bt.last, bt.last.brick_parse_dsl(join_array, bt.first, translations)]
|
306
306
|
end
|
307
|
+
skip_klass_hms = ::Brick.config.skip_index_hms[klass.name] || {}
|
307
308
|
hms.each do |k, hm|
|
309
|
+
next if skip_klass_hms.key?(k)
|
310
|
+
|
308
311
|
join_array[k] = nil # Store this relation name in our special collection for .joins()
|
309
312
|
hm_counts[k] = nil # Placeholder that will be filled in once we know the proper table alias
|
310
313
|
end
|
@@ -672,7 +675,6 @@ class Object
|
|
672
675
|
# %%% Add custom HM count columns
|
673
676
|
# %%% What happens when the PK is composite?
|
674
677
|
counts = hm_counts.each_with_object([]) { |v, s| s << "COUNT(DISTINCT #{v.last.first}.#{v.last.last.primary_key}) AS _br_#{v.first}_ct" }
|
675
|
-
puts counts.inspect
|
676
678
|
# *selects,
|
677
679
|
instance_variable_set("@#{table_name}".to_sym, ar_relation.dup._select!(*selects, *counts))
|
678
680
|
# binding.pry
|
@@ -74,6 +74,7 @@ module Brick
|
|
74
74
|
table_name = model_name.pluralize.underscore
|
75
75
|
bts, hms, associatives = ::Brick.get_bts_and_hms(@_brick_model) # This gets BT and HM and also has_many :through (HMT)
|
76
76
|
hms_columns = +'' # Used for 'index'
|
77
|
+
skip_klass_hms = ::Brick.config.skip_index_hms[model_name] || {}
|
77
78
|
hms_headers = hms.each_with_object([]) do |hm, s|
|
78
79
|
hm_assoc = hm.last
|
79
80
|
if args.first == 'index'
|
@@ -84,9 +85,15 @@ module Brick
|
|
84
85
|
hm_assoc.foreign_key
|
85
86
|
end
|
86
87
|
hms_columns << if hm_assoc.macro == :has_many
|
88
|
+
set_ct = if skip_klass_hms.key?((assoc_name = hm.first).to_sym)
|
89
|
+
'nil'
|
90
|
+
else
|
91
|
+
"#{obj_name}._br_#{assoc_name}_ct"
|
92
|
+
end
|
93
|
+
|
87
94
|
"<td>
|
88
|
-
<%= ct = #{
|
89
|
-
link_to \"#\{ct\} #{
|
95
|
+
<%= ct = #{set_ct}
|
96
|
+
link_to \"#\{ct || 'View'\} #{assoc_name}\", #{hm_assoc.klass.name.underscore.pluralize}_path({ #{hm_fk_name}: #{obj_name}.#{pk} }) unless ct&.zero? %>
|
90
97
|
</td>\n"
|
91
98
|
else # has_one
|
92
99
|
"<td>
|
@@ -177,10 +184,10 @@ def hide_bcrypt(val)
|
|
177
184
|
end %>"
|
178
185
|
|
179
186
|
if ['index', 'show', 'update'].include?(args.first)
|
180
|
-
# Example: <% bts = { "site_id" => [:site, Site, "id"], "study_id" => [:study, Study, "id"], "study_country_id" => [:study_country, StudyCountry, "id"], "user_id" => [:user, User, "id"], "role_id" => [:role, Role, "id"] } %>
|
181
187
|
css << "<% bts = { #{bts.each_with_object([]) { |v, s| s << "#{v.first.inspect} => [#{v.last.first.inspect}, #{v.last[1].name}, #{v.last[1].primary_key.inspect}]"}.join(', ')} } %>"
|
182
188
|
end
|
183
189
|
|
190
|
+
# %%% When doing schema select, if there's an ID then remove it, or if we're on a new page go to index
|
184
191
|
script = "<script>
|
185
192
|
var schemaSelect = document.getElementById(\"schema\");
|
186
193
|
var brickSchema;
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -103,10 +103,10 @@ module Brick
|
|
103
103
|
|
104
104
|
def get_bts_and_hms(model)
|
105
105
|
bts, hms = model.reflect_on_all_associations.each_with_object([{}, {}]) do |a, s|
|
106
|
-
# So that we can map an association name to any special alias name used in an AREL query
|
107
|
-
ans = (model._assoc_names[a.name] ||= [])
|
108
106
|
next if !const_defined?(a.name.to_s.singularize.camelize) && ::Brick.config.exclude_tables.include?(a.plural_name)
|
109
107
|
|
108
|
+
# So that we can map an association name to any special alias name used in an AREL query
|
109
|
+
ans = (model._assoc_names[a.name] ||= [])
|
110
110
|
ans << a.klass unless ans.include?(a.klass)
|
111
111
|
case a.macro
|
112
112
|
when :belongs_to
|
@@ -240,6 +240,12 @@ module Brick
|
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
243
|
+
# Skip showing counts for these specific has_many associations when building auto-generated #index views
|
244
|
+
# @api public
|
245
|
+
def skip_index_hms=(value)
|
246
|
+
Brick.config.skip_index_hms = value
|
247
|
+
end
|
248
|
+
|
243
249
|
# Associations to treat as a has_one
|
244
250
|
# @api public
|
245
251
|
def has_ones=(hos)
|
@@ -111,11 +111,16 @@ module Brick
|
|
111
111
|
# # to be the primary key.)
|
112
112
|
#{bar}
|
113
113
|
|
114
|
-
# # Skip creating a has_many association for these
|
114
|
+
# # Skip creating a has_many association for these (only retain the belongs_to built from this additional_reference).
|
115
115
|
# # (Uses the same exact three-part format as would define an additional_reference)
|
116
116
|
# # Say for instance that we didn't care to display the favourite colours that users have:
|
117
117
|
# Brick.exclude_hms = [['users', 'favourite_colour_id', 'colours']]
|
118
118
|
|
119
|
+
# # Skip showing counts for these specific has_many associations when building auto-generated #index views.
|
120
|
+
# # When there are related tables with a significant number of records, this can lessen the load on the database
|
121
|
+
# # considerably, sometimes fixing what might appear to be an index page that just \"hangs\" for no apparent reason.
|
122
|
+
Brick.skip_index_hms = ['User.litany_of_woes']
|
123
|
+
|
119
124
|
# # By default primary tables involved in a foreign key relationship will indicate a \"has_many\" relationship pointing
|
120
125
|
# # back to the foreign table. In order to represent a \"has_one\" association instead, an override can be provided
|
121
126
|
# # using the primary model name and the association name which you instead want to have treated as a \"has_one\":
|
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.21
|
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-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|