brick 1.0.120 → 1.0.121

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: faca98f57870f50ba6474325fa995fe70ac36b4efd4c58946553242afe7ccb86
4
- data.tar.gz: 3dd28e3cb60b74bd99209da86e302b7301e0eb844e314e7c56dde43ed4475b7e
3
+ metadata.gz: 142adfa751be46ca1115b6e6f6945ab25ad10148e55c7584eba6f91be62c6cf0
4
+ data.tar.gz: a20a11f7fc6c864fbf9c5d9b4c6f80f29c0d26380e0aa110b63183f6e0c2e3e0
5
5
  SHA512:
6
- metadata.gz: 3ccbfc86abb0a16f053ddbf0b43e0c96a6d70a9f2ab3cab95ea008d76bcba1572aaf87b5d6eb9a79a342c20b26b900c42a1dd178c6b478e6f0f8daf372bb9189
7
- data.tar.gz: 464e92a80e820c66c8ed2517593440e0752bfc4b8d7fdf3667fd662291b6663e95e417f60281647529cea7c11c0d13a3fa5c22d69142c6b880db5ae077e632d3
6
+ metadata.gz: 84c6880fcb0c2aa00ee7484053c40afc61e2f9e66af38bb677408f762002c8a990a2f68bd3f17443916e02ed1a08b1db605bc28a7e913b2841bbb1318a3dcca0
7
+ data.tar.gz: 377decd3c088a4ddc6034de54aed3885e99b10e54a5336885a4b8ed1c611e52947af99728b48ffa6bb0b5ec29babf971dea580bcfca053deb4f5fb3f60fd1877
@@ -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 |v, s|
2617
- File.read(v).split("\n").each do |line|
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
- model = line[idx + 5..-1].match(/[\s:]+([\w:]+)/)&.captures&.first
2621
- if model && abstract_activerecord_bases.exclude?(model)
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
- model.constantize
2630
+ model_name.constantize
2624
2631
  rescue
2625
2632
  end
2626
- s[model.underscore.tr('/', '.').pluralize] = [
2627
- v.start_with?(rails_root) ? v[rails_root.length + 1..-1] : v,
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
- bt_class = obj.send("#{bt.first}_type")
76
- base_class_underscored = (::Brick.existing_stis[bt_class] || bt_class).constantize.base_class._brick_index(:singular)
77
- poly_id = obj.send("#{bt.first}_id")
78
- out << link_to("#{bt_class} ##{poly_id}", send("#{base_class_underscored}_path".to_sym, poly_id)) if poly_id
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
- bt_txt = bt_class.brick_descrip(
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
- obj, descrips[0..-2].map { |id| obj.send(id.last[0..62]) }, bt_id_col
92
- )
93
- bt_txt = ::Brick::Rails.display_binary(bt_txt).html_safe if bt_txt&.encoding&.name == 'ASCII-8BIT'
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\">&lt;&lt; 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.send(id_col.to_sym) })&.first
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
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 120
8
+ TINY = 121
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
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.120
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-07 00:00:00.000000000 Z
11
+ date: 2023-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord