brick 1.0.120 → 1.0.121
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 +15 -8
- data/lib/brick/frameworks/rails/form_tags.rb +18 -10
- data/lib/brick/version_number.rb +1 -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: 142adfa751be46ca1115b6e6f6945ab25ad10148e55c7584eba6f91be62c6cf0
|
4
|
+
data.tar.gz: a20a11f7fc6c864fbf9c5d9b4c6f80f29c0d26380e0aa110b63183f6e0c2e3e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84c6880fcb0c2aa00ee7484053c40afc61e2f9e66af38bb677408f762002c8a990a2f68bd3f17443916e02ed1a08b1db605bc28a7e913b2841bbb1318a3dcca0
|
7
|
+
data.tar.gz: 377decd3c088a4ddc6034de54aed3885e99b10e54a5336885a4b8ed1c611e52947af99728b48ffa6bb0b5ec29babf971dea580bcfca053deb4f5fb3f60fd1877
|
data/lib/brick/extensions.rb
CHANGED
@@ -2613,18 +2613,25 @@ module Brick
|
|
2613
2613
|
end
|
2614
2614
|
abstract_activerecord_bases = ::Brick.eager_load_classes(true)
|
2615
2615
|
models = if Dir.exist?(model_path = "#{rails_root}/app/models")
|
2616
|
-
Dir["#{model_path}/**/*.rb"].each_with_object({}) do |
|
2617
|
-
|
2616
|
+
Dir["#{model_path}/**/*.rb"].each_with_object({}) do |path, s|
|
2617
|
+
modules = []
|
2618
|
+
File.read(path).split("\n").each do |line|
|
2619
|
+
# Capture a list of modules leading up to this class
|
2620
|
+
if line.lstrip.start_with?('module ') && (idx = line.index('module'))
|
2621
|
+
modules << line[idx + 6..-1].match(/[\s:]+([\w:]+)/)&.captures&.first
|
2622
|
+
end
|
2618
2623
|
# For all non-commented lines, look for any that start with "class " and also "< ApplicationRecord"
|
2619
|
-
if line.lstrip.start_with?('class') && (idx = line.index('class'))
|
2620
|
-
|
2621
|
-
|
2624
|
+
if line.lstrip.start_with?('class ') && (idx = line.index('class')) &&
|
2625
|
+
(model_name = line[idx + 5..-1].match(/[\s:]+([\w:]+)/)&.captures&.first)
|
2626
|
+
# Prefix model class name with module names, if any
|
2627
|
+
model_name = modules.map{|m| "#{m}::"}.join + model_name
|
2628
|
+
unless abstract_activerecord_bases.include?(model_name)
|
2622
2629
|
klass = begin
|
2623
|
-
|
2630
|
+
model_name.constantize
|
2624
2631
|
rescue
|
2625
2632
|
end
|
2626
|
-
s[
|
2627
|
-
|
2633
|
+
s[model_name.underscore.tr('/', '.').pluralize] = [
|
2634
|
+
path.start_with?(rails_root) ? path[rails_root.length + 1..-1] : path,
|
2628
2635
|
klass
|
2629
2636
|
]
|
2630
2637
|
end
|
@@ -72,10 +72,12 @@ module Brick::Rails::FormTags
|
|
72
72
|
out << '>'
|
73
73
|
if (bt = bts[col_name])
|
74
74
|
if bt[2] # Polymorphic?
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
if (poly_id = obj.send("#{bt.first}_id"))
|
76
|
+
# Was: obj.send("#{bt.first}_type")
|
77
|
+
bt_class = obj.send(obj.class.reflect_on_association(bt.first).foreign_type)
|
78
|
+
base_class_underscored = (::Brick.existing_stis[bt_class] || bt_class).constantize.base_class._brick_index(:singular)
|
79
|
+
out << link_to("#{bt_class} ##{poly_id}", send("#{base_class_underscored}_path".to_sym, poly_id))
|
80
|
+
end
|
79
81
|
else # BT or HOT
|
80
82
|
bt_class = bt[1].first.first
|
81
83
|
descrips = bt_descrip[bt.first][bt_class]
|
@@ -84,13 +86,19 @@ module Brick::Rails::FormTags
|
|
84
86
|
elsif descrips.length == 1
|
85
87
|
[obj.class.reflect_on_association(bt.first)&.foreign_key]
|
86
88
|
else
|
87
|
-
descrips.last
|
89
|
+
# Was: descrips.last -- but the ID stuff is not coming through anymore
|
90
|
+
[bt.first]
|
88
91
|
end
|
89
|
-
|
92
|
+
txt_parts = descrips.map do |id|
|
93
|
+
obj2 = obj
|
94
|
+
id[0..-2].each { |ref| obj2 = obj2&.send(ref) }
|
90
95
|
# 0..62 because Postgres column names are limited to 63 characters
|
91
|
-
|
92
|
-
|
93
|
-
|
96
|
+
obj2&.send(id.last[0..62])
|
97
|
+
end
|
98
|
+
unless txt_parts.compact.empty?
|
99
|
+
bt_txt = bt_class.brick_descrip(obj, txt_parts, bt_id_col)
|
100
|
+
bt_txt = ::Brick::Rails.display_binary(bt_txt).html_safe if bt_txt&.encoding&.name == 'ASCII-8BIT'
|
101
|
+
end
|
94
102
|
bt_txt ||= "<span class=\"orphan\"><< Orphaned ID: #{val} >></span>" if val
|
95
103
|
bt_id = bt_id_col&.map { |id_col| obj.respond_to?(id_sym = id_col.to_sym) ? obj.send(id_sym) : id_col }
|
96
104
|
out << (bt_id&.first ? link_to(bt_txt, send("#{bt_class.base_class._brick_index(:singular)}_path".to_sym, bt_id)) : bt_txt || '')
|
@@ -102,7 +110,7 @@ module Brick::Rails::FormTags
|
|
102
110
|
hm_klass = (col = cols[col_name])[1]
|
103
111
|
if col[2] == 'HO'
|
104
112
|
descrips = bt_descrip[col_name.to_sym][hm_klass]
|
105
|
-
if (ho_id = (ho_id_col = descrips.last).map { |id_col| obj.
|
113
|
+
if (ho_id = (ho_id_col = descrips.last).map { |id_col| obj.respond_to?(id_sym = id_col.to_sym) && obj.send(id_sym) })&.first
|
106
114
|
ho_txt = hm_klass.brick_descrip(obj, descrips[0..-2].map { |id| obj.send(id.last[0..62]) }, ho_id_col)
|
107
115
|
out << link_to(ho_txt, send("#{hm_klass.base_class._brick_index(:singular)}_path".to_sym, ho_id))
|
108
116
|
end
|
data/lib/brick/version_number.rb
CHANGED
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.121
|
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-03-
|
11
|
+
date: 2023-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|