brick 1.0.93 → 1.0.94
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/extensions.rb +11 -7
- data/lib/brick/frameworks/rails/engine.rb +19 -11
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +5 -4
- 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: 4b4de74edca4a5dd2c7d57d23dda2aa4cbc966402db4f2d0490dfeb741224dd5
|
4
|
+
data.tar.gz: fe905ed82bf8ae8f249e5ce3fe1646cb6366caf3343086ea8ba597e51525f521
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45d2dda76345ab043c4e62d92b5e12a466ffec892e1ce63b540bd6427fcecfa777739732754d554f78b5803599fca1390fa2d38cb8f0acd9b0ffd8e5c6dd34aa
|
7
|
+
data.tar.gz: 65b73535a5874fe5b3c46fec455fe62857259c7d56b68241a729f2c928a47e0fdcc71988a3b7ead506de717fae71932007855efaf18dd8866b920da2c6d5c779
|
data/lib/brick/extensions.rb
CHANGED
@@ -245,12 +245,15 @@ module ActiveRecord
|
|
245
245
|
end
|
246
246
|
|
247
247
|
def self.bt_link(assoc_name)
|
248
|
-
|
248
|
+
assoc_html_name = unless (assoc_name = assoc_name.to_s).camelize == name
|
249
|
+
CGI.escapeHTML(assoc_name)
|
250
|
+
end
|
249
251
|
model_path = ::Rails.application.routes.url_helpers.send("#{_brick_index}_path".to_sym)
|
252
|
+
model_path << "?#{self.inheritance_column}=#{self.name}" if self != base_class
|
250
253
|
av_class = Class.new.extend(ActionView::Helpers::UrlHelper)
|
251
254
|
av_class.extend(ActionView::Helpers::TagHelper) if ActionView.version < ::Gem::Version.new('7')
|
252
|
-
link = av_class.link_to(name, model_path)
|
253
|
-
|
255
|
+
link = av_class.link_to(assoc_html_name ? name : assoc_name, model_path)
|
256
|
+
assoc_html_name ? "#{assoc_name}-#{link}".html_safe : link
|
254
257
|
end
|
255
258
|
|
256
259
|
def self._brick_index(mode = nil)
|
@@ -542,7 +545,7 @@ module ActiveRecord
|
|
542
545
|
field_tbl_name = "\"#{field_tbl_name}\"" if ::Brick.is_oracle && rel_dupe.brick_links.values.include?(field_tbl_name)
|
543
546
|
|
544
547
|
# Postgres can not use DISTINCT with any columns that are XML, so for any of those just convert to text
|
545
|
-
is_xml = is_distinct && Brick.relations[
|
548
|
+
is_xml = is_distinct && Brick.relations[k1.table_name]&.[](:cols)&.[](sel_col.last)&.first&.start_with?('xml')
|
546
549
|
# If it's not unique then also include the belongs_to association name before the column name
|
547
550
|
if used_col_aliases.key?(col_alias = "br_fk_#{v.first}__#{sel_col.last}")
|
548
551
|
col_alias = "br_fk_#{v.first}__#{v1[idx][-2..-1].map(&:to_s).join('__')}"
|
@@ -2310,7 +2313,7 @@ module Brick
|
|
2310
2313
|
rails_root = ::Rails.root.to_s
|
2311
2314
|
migrations = if Dir.exist?(mig_path = ActiveRecord::Migrator.migrations_paths.first || "#{rails_root}/db/migrate")
|
2312
2315
|
Dir["#{mig_path}/**/*.rb"].each_with_object(Hash.new { |h, k| h[k] = [] }) do |v, s|
|
2313
|
-
File.read(v).split("\n").
|
2316
|
+
File.read(v).split("\n").each_with_index do |line, line_idx|
|
2314
2317
|
# For all non-commented lines, look for any that have "create_table", "alter_table", or "drop_table"
|
2315
2318
|
if !line.lstrip.start_with?('#') &&
|
2316
2319
|
(idx = (line.index('create_table ') || line.index('create_table('))&.+(13)) ||
|
@@ -2318,8 +2321,9 @@ module Brick
|
|
2318
2321
|
(idx = (line.index('drop_table ') || line.index('drop_table('))&.+(11))
|
2319
2322
|
tbl = line[idx..-1].match(/([:'"\w\.]+)/)&.captures&.first
|
2320
2323
|
if tbl
|
2321
|
-
|
2322
|
-
|
2324
|
+
v = v[(rails_root.length)..-1] if v.start_with?(rails_root)
|
2325
|
+
v = v[1..-1] if v.start_with?('/')
|
2326
|
+
s[tbl.tr(':\'"', '').pluralize] << [v, line_idx + 1]
|
2323
2327
|
end
|
2324
2328
|
end
|
2325
2329
|
end
|
@@ -141,10 +141,10 @@ module Brick
|
|
141
141
|
next unless @_brick_model.instance_methods.include?(through) &&
|
142
142
|
(associative = @_brick_model._br_associatives.fetch(hm.first, nil))
|
143
143
|
|
144
|
-
tbl_nm = if (source = hm_assoc.source_reflection).macro == :
|
145
|
-
hm_assoc.through_reflection&.name # for standard HMT, which is HM -> BT
|
146
|
-
else
|
144
|
+
tbl_nm = if (source = hm_assoc.source_reflection).macro == :has_many
|
147
145
|
source.inverse_of&.name # For HM -> HM style HMT
|
146
|
+
else # belongs_to or has_one
|
147
|
+
hm_assoc.through_reflection&.name # for standard HMT, which is HM -> BT
|
148
148
|
end
|
149
149
|
# If there is no inverse available for the source belongs_to association, make one based on the class name
|
150
150
|
unless tbl_nm
|
@@ -203,7 +203,6 @@ module Brick
|
|
203
203
|
# environment or whatever, then get either the controllers or routes list instead
|
204
204
|
prefix = "#{::Brick.config.path_prefix}/" if ::Brick.config.path_prefix
|
205
205
|
table_options = (::Brick.relations.keys - ::Brick.config.exclude_tables).each_with_object({}) do |tbl, s|
|
206
|
-
binding.pry if tbl.is_a?(Symbol)
|
207
206
|
if (tbl_parts = tbl.split('.')).first == apartment_default_schema
|
208
207
|
tbl = tbl_parts.last
|
209
208
|
end
|
@@ -911,7 +910,9 @@ erDiagram
|
|
911
910
|
end
|
912
911
|
unless @_brick_sequence # If no sequence is defined, start with all inclusions
|
913
912
|
cust_cols = #{model_name}._br_cust_cols
|
914
|
-
|
913
|
+
# HOT columns, kept as symbols
|
914
|
+
hots = #{model_name}._br_bt_descrip.keys.select { |k| bts.key?(k) }
|
915
|
+
@_brick_sequence = col_keys + cust_cols.keys + hots + #{(hms_keys).inspect}.reject { |assoc_name| @_brick_incl&.exclude?(assoc_name) }
|
915
916
|
end
|
916
917
|
@_brick_sequence.reject! { |nm| @_brick_excl.include?(nm) } if @_brick_excl # Reject exclusions
|
917
918
|
@_brick_sequence.each_with_object(+'') do |col_name, s|
|
@@ -928,8 +929,12 @@ erDiagram
|
|
928
929
|
elsif col # HM column
|
929
930
|
s << \"<th#\{' x-order=\"' + col_name + '\"' if true}>#\{col[2]} \"
|
930
931
|
s << (col.first ? \"#\{col[3]}\" : \"#\{link_to(col[3], send(\"#\{col[1]._brick_index}_path\"))}\")
|
931
|
-
elsif
|
932
|
+
elsif cust_cols.key?(col_name) # Custom column
|
932
933
|
s << \"<th x-order=\\\"#\{col_name}\\\">#\{col_name}\"
|
934
|
+
elsif col_name.is_a?(Symbol) && (hot = bts[col_name]) # has_one :through
|
935
|
+
s << \"<th x-order=\\\"#\{hot.first.to_s}\\\">HOT \" +
|
936
|
+
hot[1].map { |hot_pair| hot_pair.first.bt_link(col_name) }.join(' ')
|
937
|
+
hot[1].first
|
933
938
|
else # Bad column name!
|
934
939
|
s << \"<th title=\\\"<< Unknown column >>\\\">#\{col_name}\"
|
935
940
|
end
|
@@ -947,14 +952,16 @@ erDiagram
|
|
947
952
|
<td><%= link_to '⇛', #{path_obj_name}_path(slashify(#{obj_pk})), { class: 'big-arrow' } %></td>" if obj_pk}
|
948
953
|
<% @_brick_sequence.each do |col_name|
|
949
954
|
val = #{obj_name}.attributes[col_name] %>
|
950
|
-
<td<%= ' class=\"dimmed\"'.html_safe unless cols.key?(col_name) || (cust_col = cust_cols[col_name])
|
955
|
+
<td<%= ' class=\"dimmed\"'.html_safe unless cols.key?(col_name) || (cust_col = cust_cols[col_name]) ||
|
956
|
+
(col_name.is_a?(Symbol) && bts.key?(col_name)) # HOT
|
957
|
+
%>><%
|
951
958
|
if (bt = bts[col_name])
|
952
959
|
if bt[2] # Polymorphic?
|
953
960
|
bt_class = #{obj_name}.send(\"#\{bt.first}_type\")
|
954
961
|
base_class_underscored = (::Brick.existing_stis[bt_class] || bt_class).constantize.base_class._brick_index(:singular)
|
955
962
|
poly_id = #{obj_name}.send(\"#\{bt.first}_id\")
|
956
963
|
%><%= link_to(\"#\{bt_class} ##\{poly_id}\", send(\"#\{base_class_underscored}_path\".to_sym, poly_id)) if poly_id %><%
|
957
|
-
else
|
964
|
+
else # BT or HOT
|
958
965
|
bt_class = bt[1].first.first
|
959
966
|
descrips = @_brick_bt_descrip[bt.first][bt_class]
|
960
967
|
bt_id_col = if descrips.nil?
|
@@ -1041,7 +1048,7 @@ erDiagram
|
|
1041
1048
|
%>
|
1042
1049
|
<tr>
|
1043
1050
|
<td><%= begin
|
1044
|
-
kls = Object.const_get(::Brick.relations
|
1051
|
+
kls = Object.const_get(::Brick.relations.fetch(r[0], nil)&.fetch(:class_name, nil))
|
1045
1052
|
rescue
|
1046
1053
|
end
|
1047
1054
|
kls ? link_to(r[0], send(\"#\{kls._brick_index}_path\".to_sym)) : r[0] %></td>
|
@@ -1051,8 +1058,9 @@ erDiagram
|
|
1051
1058
|
' class=\"dimmed\"'
|
1052
1059
|
end&.html_safe %>><%= # Table
|
1053
1060
|
r[1] %></td>
|
1054
|
-
<td<%=
|
1055
|
-
|
1061
|
+
<td<%= lines = r[2]&.map { |line| \"#\{line.first}:#\{line.last}\" }
|
1062
|
+
' class=\"dimmed\"'.html_safe unless r[2] %>><%= # Migration
|
1063
|
+
lines&.join('<br>')&.html_safe %></td>
|
1056
1064
|
<td<%= ' class=\"dimmed\"'.html_safe unless r[3] %>><%= # Model
|
1057
1065
|
r[3] %></td>
|
1058
1066
|
<td<%= ' class=\"dimmed\"'.html_safe unless r[4] %>><%= # Route
|
data/lib/brick/version_number.rb
CHANGED
data/lib/brick.rb
CHANGED
@@ -211,12 +211,13 @@ module Brick
|
|
211
211
|
else
|
212
212
|
s.first[a.foreign_key.to_s] = [a.name, a.klass]
|
213
213
|
end
|
214
|
-
else # This gets
|
215
|
-
if through
|
214
|
+
else # This gets all forms of has_many and has_one
|
215
|
+
if through # has_many :through or has_one :through
|
216
216
|
is_invalid_source = nil
|
217
217
|
begin
|
218
|
-
if a.through_reflection
|
219
|
-
|
218
|
+
if a.through_reflection.macro != :has_many # This HM goes through either a belongs_to or a has_one, so essentially a HOT?
|
219
|
+
# Treat it like a belongs_to - just keyed on the association name instead of a foreign_key
|
220
|
+
s.first[a.name] = [a.name, a.klass]
|
220
221
|
next
|
221
222
|
elsif !a.source_reflection # Had considered: a.active_record.reflect_on_association(a.source_reflection_name).nil?
|
222
223
|
is_invalid_source = true
|
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.94
|
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-
|
11
|
+
date: 2022-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|