brick 1.0.119 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dfec2ebe501c46c17a7466bd98a9fb510ce6676f74c9b914da52e789e279036
4
- data.tar.gz: 803598a5b59f73e81ed94079dd2b7dd55328c5c12de6d6968937b6518b68cef7
3
+ metadata.gz: 142adfa751be46ca1115b6e6f6945ab25ad10148e55c7584eba6f91be62c6cf0
4
+ data.tar.gz: a20a11f7fc6c864fbf9c5d9b4c6f80f29c0d26380e0aa110b63183f6e0c2e3e0
5
5
  SHA512:
6
- metadata.gz: 1618ef1ff14f0198d45aa0aafc5ee9e0272c82a886b0129e14cfe6c47fea1cbb55c76f32cf2a98eb93915c68a62275ad53e5ab32621da45b9a7397e2d1f95f3f
7
- data.tar.gz: f34063a9ebc164bf352d96b1149f1ed501a351c3e786219a29593be13359162c9bb140cf822d9ce1494be9ea43b655afb0422008d6fcc64f59ee7050a1e84072
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
@@ -2,6 +2,39 @@
2
2
 
3
3
  module Brick
4
4
  module Rails
5
+ def self.display_binary(val)
6
+ @image_signatures ||= { (+"\xFF\xD8\xFF\xEE").force_encoding('ASCII-8BIT') => 'jpeg',
7
+ (+"\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46\x00\x01").force_encoding('ASCII-8BIT') => 'jpeg',
8
+ (+"\x89PNG\r\n\x1A\n").force_encoding('ASCII-8BIT') => 'png',
9
+ '<svg' => 'svg+xml', # %%% Not yet very good detection for SVG
10
+ (+'BM').force_encoding('ASCII-8BIT') => 'bmp',
11
+ (+'GIF87a').force_encoding('ASCII-8BIT') => 'gif',
12
+ (+'GIF89a').force_encoding('ASCII-8BIT') => 'gif' }
13
+
14
+ if val[0..1] == "\x15\x1C" # One of those goofy Microsoft OLE containers?
15
+ package_header_length = val[2..3].bytes.reverse.inject(0) {|m, b| (m << 8) + b }
16
+ # This will often be just FF FF FF FF
17
+ # object_size = val[16..19].bytes.reverse.inject(0) {|m, b| (m << 8) + b }
18
+ friendly_and_class_names = val[20...package_header_length].split("\0")
19
+ object_type_name_length = val[package_header_length + 8..package_header_length+11].bytes.reverse.inject(0) {|m, b| (m << 8) + b }
20
+ friendly_and_class_names << val[package_header_length + 12...package_header_length + 12 + object_type_name_length].strip
21
+ # friendly_and_class_names will now be something like: ['Bitmap Image', 'Paint.Picture', 'PBrush']
22
+ real_object_size = val[package_header_length + 20 + object_type_name_length..package_header_length + 23 + object_type_name_length].bytes.reverse.inject(0) {|m, b| (m << 8) + b }
23
+ object_start = package_header_length + 24 + object_type_name_length
24
+ val = val[object_start...object_start + real_object_size]
25
+ end
26
+
27
+ if (signature = @image_signatures.find { |k, _v| val[0...k.length] == k })
28
+ if val.length < 500_000
29
+ "<img src=\"data:image/#{signature.last};base64,#{Base64.encode64(val)}\">"
30
+ else
31
+ "&lt;&nbsp;#{signature.last} image, #{val.length} bytes&nbsp;>"
32
+ end
33
+ else
34
+ "&lt;&nbsp;Binary, #{val.length} bytes&nbsp;>"
35
+ end
36
+ end
37
+
5
38
  # See http://guides.rubyonrails.org/engines.html
6
39
  class Engine < ::Rails::Engine
7
40
  JS_CHANGEOUT = "function changeout(href, param, value, trimAfter) {
@@ -938,7 +971,7 @@ def display_value(col_type, val)
938
971
  '(Add RGeo gem to parse geometry detail)'
939
972
  end
940
973
  when :binary
941
- display_binary(val) if val
974
+ ::Brick::Rails.display_binary(val) if val
942
975
  else
943
976
  if col_type
944
977
  hide_bcrypt(val, col_type == :xml)
@@ -948,39 +981,6 @@ def display_value(col_type, val)
948
981
  end
949
982
  end
950
983
 
951
- def image_signatures
952
- @image_signatures ||= { \"\\xFF\\xD8\\xFF\\xEE\".force_encoding('ASCII-8BIT') => 'jpeg',
953
- \"\\xFF\\xD8\\xFF\\xE0\\x00\\x10\\x4A\\x46\\x49\\x46\\x00\\x01\".force_encoding('ASCII-8BIT') => 'jpeg',
954
- \"\\x89PNG\\r\\n\\x1A\\n\".force_encoding('ASCII-8BIT') => 'png',
955
- '<svg' => 'svg+xml', # %%% Not yet very good detection for SVG
956
- 'BM'.force_encoding('ASCII-8BIT') => 'bmp',
957
- 'GIF87a'.force_encoding('ASCII-8BIT') => 'gif',
958
- 'GIF89a'.force_encoding('ASCII-8BIT') => 'gif' }
959
- end
960
- def display_binary(val)
961
- if val[0..1] == \"\\x15\\x1C\" # One of those goofy Microsoft OLE containers?
962
- package_header_length = val[2..3].bytes.reverse.inject(0) {|m, b| (m << 8) + b }
963
- # This will often be just FF FF FF FF
964
- # object_size = val[16..19].bytes.reverse.inject(0) {|m, b| (m << 8) + b }
965
- friendly_and_class_names = val[20...package_header_length].split(\"\\0\")
966
- object_type_name_length = val[package_header_length + 8..package_header_length+11].bytes.reverse.inject(0) {|m, b| (m << 8) + b }
967
- friendly_and_class_names << val[package_header_length + 12...package_header_length + 12 + object_type_name_length].strip
968
- # friendly_and_class_names will now be something like: ['Bitmap Image', 'Paint.Picture', 'PBrush']
969
- real_object_size = val[package_header_length + 20 + object_type_name_length..package_header_length + 23 + object_type_name_length].bytes.reverse.inject(0) {|m, b| (m << 8) + b }
970
- object_start = package_header_length + 24 + object_type_name_length
971
- val = val[object_start...object_start + real_object_size]
972
- end
973
- if (signature = image_signatures.find { |k, _v| val[0...k.length] == k })
974
- if val.length < 500_000
975
- \"<img src=\\\"data:image/#\{signature.last};base64,#\{Base64.encode64(val)}\\\">\"
976
- else
977
- \"&lt;&nbsp;#\{signature.last} image, #\{val.length} bytes&nbsp;>\"
978
- end
979
- else
980
- \"&lt;&nbsp;Binary, #\{val.length} bytes&nbsp;>\"
981
- end
982
- end
983
-
984
984
  # Accommodate composite primary keys that include strings with forward-slash characters
985
985
  def slashify(*vals)
986
986
  vals.map { |val_part| val_part.is_a?(String) ? val_part.gsub('/', '^^sl^^') : val_part }
@@ -1685,7 +1685,7 @@ end
1685
1685
  if val.length < 31 && (val.length - 6) % 8 == 0 && val[0..5].bytes == [230, 16, 0, 0, 1, 12]
1686
1686
  display_value('geography', val)
1687
1687
  else
1688
- display_binary(val)
1688
+ ::Brick::Rails.display_binary(val)
1689
1689
  end.html_safe
1690
1690
  end %>
1691
1691
  <% when :primary_key
@@ -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 = 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 = 119
8
+ TINY = 121
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
@@ -268,7 +268,7 @@ if ActiveRecord::Base.respond_to?(:brick_select) && !::Brick.initializer_loaded
268
268
  # # FRIENDLY DSL
269
269
 
270
270
  # # A simple DSL is available to allow more user-friendly display of objects. Normally a user object might be shown
271
- # # as its first non-metadata column, or if that is not available then something like \"User #45\" where 45 is that
271
+ # # as its first non-metadata column, or if that is not available then something like \"User #42\" where 42 is that
272
272
  # # object's ID. If there is no primary key then even that is not possible, so the object's .to_s method is called.
273
273
  # # To override these defaults and specify exactly what you want shown, such as first names and last names for a
274
274
  # # user, then you can use model_descrips like this, putting expressions with property references in square brackets:
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.119
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-05 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