brick 1.0.113 → 1.0.115

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: f6cede45ed1fd983a2199fb279dffad0ecd02e51c7ed31cec6d46fccbc799e7c
4
- data.tar.gz: 65eb5df73a7869b1bbe3ac128a69b4fda257e9dc098e77dc65c75d8f593756d7
3
+ metadata.gz: 6e92e1445b603e8611ad927b8864b6ff04fd819d2f2243051d109d0894838e0d
4
+ data.tar.gz: b76bc7adf85927a5ff4988027a0d7ff1d40b84d4a80531d23390867bcca0fc5e
5
5
  SHA512:
6
- metadata.gz: 0e506c2b4d00a1402e232f48c9eb95fc1edfb201a4b2d46ce8fd2a29d0f6a62e5d954ba84dfad4ccab2ff2c5c972d32478873e1f5c7ddf19bdfcca24894b0d1e
7
- data.tar.gz: ee7dd85c423043b10efb60075716e3464db2645ac642fa43f457cf1b05c98a52cb7645e58e3a8208be8fd94b3a4b74f6b7d5e3102d890d087542a04b7e8cc7ec
6
+ metadata.gz: 9caa3d9fdbc5229123058ec526482bf4c6926c42a44012d974a26d4f94f6f0e2f1dd2040ee76b1fbec21e431ea479694030365a1982878c6100245a607803260
7
+ data.tar.gz: 0e09bb3d9556bc8b4a442eccc9f19a374684c901dc0f9769030313ebdc57248f31a994e5deb7dbde394f066187b961eab169545e3466ab0851cb6df7636c62f1
data/lib/brick/config.rb CHANGED
@@ -213,6 +213,14 @@ module Brick
213
213
  @mutex.synchronize { @polymorphics = polys }
214
214
  end
215
215
 
216
+ def json_columns
217
+ @mutex.synchronize { @json_columns ||= {} }
218
+ end
219
+
220
+ def json_columns=(cols)
221
+ @mutex.synchronize { @json_columns = cols }
222
+ end
223
+
216
224
  def model_descrips
217
225
  @mutex.synchronize { @model_descrips ||= {} }
218
226
  end
@@ -274,7 +274,7 @@ module ActiveRecord
274
274
  tbl_parts.unshift(::Brick.config.path_prefix) if ::Brick.config.path_prefix
275
275
  index = tbl_parts.map(&:underscore).join(separator)
276
276
  # Rails applies an _index suffix to that route when the resource name is singular
277
- index << '_index' if mode != :singular && index == index.singularize
277
+ index << '_index' if mode != :singular && separator == '_' && index == index.singularize
278
278
  index
279
279
  end
280
280
 
@@ -972,7 +972,10 @@ Module.class_exec do
972
972
  end
973
973
  # puts "#{self.name} - #{args.first}"
974
974
  desired_classname = (self == Object || !name) ? requested : "#{name}::#{requested}"
975
- if ((is_defined = self.const_defined?(args.first)) && (possible = self.const_get(args.first)) && possible.name == desired_classname) ||
975
+ if ((is_defined = self.const_defined?(args.first)) && (possible = self.const_get(args.first)) &&
976
+ # Reset `possible` if it's a controller request that's not a perfect match
977
+ # Was: (possible = nil) but changed to #local_variable_set in order to suppress the "= should be ==" warning
978
+ (possible.name == desired_classname || (is_controller && binding.local_variable_set(:possible, nil)))) ||
976
979
  # Try to require the respective Ruby file
977
980
  ((filename = ActiveSupport::Dependencies.search_for_file(desired_classname.underscore) ||
978
981
  (self != Object && ActiveSupport::Dependencies.search_for_file((desired_classname = requested).underscore))
@@ -983,7 +986,7 @@ Module.class_exec do
983
986
  # then return what we've found.
984
987
  (is_defined && !::Brick.is_eager_loading) # Used to also have: && possible != self
985
988
  if (!brick_root && (filename || possible.instance_of?(Class))) ||
986
- (possible.instance_of?(Module) && possible.module_parent == self) ||
989
+ (possible.instance_of?(Module) && possible&.module_parent == self) ||
987
990
  (possible.instance_of?(Class) && possible == self) # Are we simply searching for ourselves?
988
991
  return possible
989
992
  end
@@ -82,6 +82,15 @@ function linkSchemas() {
82
82
  }
83
83
  };
84
84
  "
85
+ BRICK_SVG = "<svg version=\"1.1\" style=\"display: inline; padding-left: 0.5em;\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"
86
+ viewBox=\"0 0 58 58\" height=\"1.4em\" xml:space=\"preserve\">
87
+ <g>
88
+ <polygon style=\"fill:#C2615F;\" points=\"58,15.831 19.106,35.492 0,26.644 40,6\"/>
89
+ <polygon style=\"fill:#6D4646;\" points=\"19,52 0,43.356 0,26.644 19,35\"/>
90
+ <polygon style=\"fill:#894747;\" points=\"58,31.559 19,52 19,35 58,15.831\"/>
91
+ </g>
92
+ </svg>
93
+ ".html_safe
85
94
 
86
95
  # paths['app/models'] << 'lib/brick/frameworks/active_record/models'
87
96
  config.brick = ActiveSupport::OrderedOptions.new
@@ -245,16 +254,8 @@ window.addEventListener(\"popstate\", linkSchemas);
245
254
  @_name = name || ''
246
255
  end
247
256
  def to_s
248
- @_name.html_safe + @vc.instance_variable_get(:@__vc_helpers)&.link_to_brick(nil,
249
- "<svg version=\"1.1\" style=\"display: inline; padding-left: 0.5em;\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"
250
- viewBox=\"0 0 58 58\" height=\"1.4em\" xml:space=\"preserve\">
251
- <g>
252
- <polygon style=\"fill:#C2615F;\" points=\"58,15.831 19.106,35.492 0,26.644 40,6\"/>
253
- <polygon style=\"fill:#6D4646;\" points=\"19,52 0,43.356 0,26.644 19,35\"/>
254
- <polygon style=\"fill:#894747;\" points=\"58,31.559 19,52 19,35 58,15.831\"/>
255
- </g>
256
- </svg>
257
- ".html_safe,
257
+ @_name.to_s.html_safe + @vc.instance_variable_get(:@__vc_helpers)&.link_to_brick(nil,
258
+ BRICK_SVG,
258
259
  { title: "#{@_name} in Brick" }
259
260
  )
260
261
  end
@@ -298,12 +299,59 @@ window.addEventListener(\"popstate\", linkSchemas);
298
299
  )
299
300
  nil
300
301
  else # This is either a non-Avo request or a proper Avo request, so carry on
301
- _brick_url_for(options, *args)
302
+ begin
303
+ _brick_url_for(options, *args)
304
+ rescue
305
+ # Last-ditch effort in case we were in yet a different RouteSet
306
+ unless (rar = ::Rails.application.routes) == self
307
+ rar.url_for(options, *args)
308
+ end
309
+ end
302
310
  end
303
311
  end
304
312
  end
305
313
  end # Avo compatibility
306
314
 
315
+ # ActiveAdmin compatibility
316
+ if Object.const_defined?('ActiveAdmin') && ::ActiveAdmin.application&.site_title.present?
317
+ ::ActiveAdmin.class_exec do
318
+ class << self
319
+ ActiveAdmin.load!
320
+ alias _brick_routes routes
321
+ def routes(*args)
322
+ ::Brick.relations.each do |k, v|
323
+ next if k == 'active_admin_comments'
324
+
325
+ begin
326
+ if (class_name = Object.const_get(v.fetch(:class_name, nil)))
327
+ ::ActiveAdmin.register(class_name) { config.clear_batch_actions! }
328
+ end
329
+ rescue
330
+ end
331
+ end
332
+ _brick_routes(*args)
333
+ end
334
+ end
335
+ end
336
+ ::ActiveAdmin::Views::TitleBar.class_exec do
337
+ alias _brick_build_title_tag build_title_tag
338
+ def build_title_tag
339
+ if klass = begin
340
+ aa_id = helpers.instance_variable_get(:@current_tab)&.id
341
+ ::Brick.relations.fetch(aa_id, nil)&.fetch(:class_name, nil)&.constantize
342
+ rescue
343
+ end
344
+ h2((@title + link_to_brick(nil,
345
+ BRICK_SVG, # This would do well to be sized a bit smaller
346
+ { title: "#{@_name} in Brick" }
347
+ )).html_safe)
348
+ else
349
+ _brick_build_title_tag # Revert to the original
350
+ end
351
+ end
352
+ end
353
+ end
354
+
307
355
  # ====================================
308
356
  # Dynamically create generic templates
309
357
  # ====================================
@@ -1365,7 +1413,7 @@ erDiagram
1365
1413
  <% end %>
1366
1414
  </table>
1367
1415
  <%
1368
- if (description = (relation = Brick.relations[#{model_name}.table_name])&.fetch(:description, nil)) %><%=
1416
+ if (description = (relation = Brick.relations[tbl_name = #{model_name}.table_name])&.fetch(:description, nil)) %><%=
1369
1417
  description %><br><%
1370
1418
  end
1371
1419
  %><%= link_to '(See all #{obj_name.pluralize})', #{@_brick_model._brick_index}_path %>
@@ -1437,7 +1485,13 @@ end
1437
1485
  \"<span class=\\\"orphan\\\">Orphaned ID: #\{val}</span>\".html_safe
1438
1486
  end %>
1439
1487
  <% else
1440
- col_type = col&.sql_type == 'geography' ? col.sql_type : col&.type
1488
+ col_type = if ::Brick.config.json_columns[tbl_name]&.include?(k)
1489
+ :json
1490
+ elsif col&.sql_type == 'geography'
1491
+ col.sql_type
1492
+ else
1493
+ col&.type
1494
+ end
1441
1495
  case (col_type ||= col&.sql_type)
1442
1496
  when :string, :text %>
1443
1497
  <% if is_bcrypt?(val) # || .readonly?
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 113
8
+ TINY = 115
9
9
 
10
10
  # PRE is nil unless it's a pre-release (beta, RC, etc.)
11
11
  PRE = nil
data/lib/brick.rb CHANGED
@@ -458,6 +458,11 @@ module Brick
458
458
  Brick.config.polymorphics = polys || {}
459
459
  end
460
460
 
461
+ # @api public
462
+ def json_columns=(cols)
463
+ Brick.config.json_columns = cols
464
+ end
465
+
461
466
  # DSL templates for individual models to provide prettier descriptions of objects
462
467
  # @api public
463
468
  def model_descrips=(descrips)
@@ -529,7 +534,7 @@ module Brick
529
534
  You might be missing an STI namespace prefix entry for these tables: #{missing_stis.keys.join(', ')}.
530
535
  In config/initializers/brick.rb appropriate entries would look something like:
531
536
  Brick.sti_namespace_prefixes = {"
532
- puts missing_stis.map { |_k, missing_sti| "\n '::#{missing_sti}' => 'SomeParentModel'" }.join(',')
537
+ puts missing_stis.map { |_k, missing_sti| "\n '#{missing_sti}' => 'SomeParentModel'" }.join(',')
533
538
  puts " }
534
539
  (Just trade out SomeParentModel with some more appropriate one.)"
535
540
  end
@@ -655,7 +660,7 @@ In config/initializers/brick.rb appropriate entries would look something like:
655
660
  module RouteSet
656
661
  def finalize!
657
662
  routeset_to_use = ::Rails.application.routes
658
- return super unless self == routeset_to_use
663
+ return super if self != routeset_to_use || ::Brick.routes_done
659
664
 
660
665
  path_prefix = ::Brick.config.path_prefix
661
666
  existing_controllers = routes.each_with_object({}) do |r, s|
@@ -859,6 +864,17 @@ In config/initializers/brick.rb appropriate entries would look something like:
859
864
  end
860
865
  end
861
866
  end
867
+
868
+ # Trestle compatibility
869
+ if Object.const_defined?('Trestle') && ::Trestle.config.options&.key?(:site_title) &&
870
+ !Object.const_defined?("#{(res_name = resource_name.tr('/', '_')).camelize}Admin")
871
+ begin
872
+ ::Trestle.resource(res_sym = res_name.to_sym, model: class_name&.constantize) do
873
+ menu { item res_sym, icon: "fa fa-star" }
874
+ end
875
+ rescue
876
+ end
877
+ end
862
878
  end
863
879
 
864
880
  if ::Brick.config.add_status && instance_variable_get(:@set).named_routes.names.exclude?(:brick_status)
@@ -907,7 +923,6 @@ In config/initializers/brick.rb appropriate entries would look something like:
907
923
  end
908
924
  end
909
925
 
910
- ::Brick.routes_done = true
911
926
  puts "\n" if tables.present? || views.present?
912
927
  if tables.present?
913
928
  puts "Classes that can be built from tables:#{' ' * (table_class_length - 38)} Path:"
@@ -921,6 +936,7 @@ In config/initializers/brick.rb appropriate entries would look something like:
921
936
  end
922
937
  end
923
938
  end
939
+ ::Brick.routes_done = true
924
940
  super
925
941
  end
926
942
  end
@@ -963,6 +979,21 @@ module ::Rails
963
979
  end
964
980
  end
965
981
 
982
+ # # Support for when a table or view is named just 's'
983
+ # ActiveSupport::Inflector.class_eval do
984
+ # class << self
985
+ # alias _brick_singularize singularize
986
+ # def singularize(word, locale = :en)
987
+ # if word.present? && ((ret = _brick_singularize(word, locale)).empty? || ret[-1] == '/')
988
+ # # puts word
989
+ # # binding.pry if ret.empty? || ret[-1] == '/'
990
+ # ret << 's'
991
+ # end
992
+ # ret
993
+ # end
994
+ # end
995
+ # end
996
+
966
997
  # Major compatibility fixes for ActiveRecord < 4.2
967
998
  # ================================================
968
999
  ActiveSupport.on_load(:active_record) do
@@ -261,6 +261,10 @@ if ActiveRecord::Base.respond_to?(:brick_select) && !::Brick.initializer_loaded
261
261
  # # Designated by <table name>.<column name>
262
262
  # Brick.not_nullables = ['users.name']
263
263
 
264
+ # # String or text columns which for editing purposes should be treated as JSON. Format for the hash is:
265
+ # # { table_name => [column names] }
266
+ # Brick.json_columns = { 'users' => ['info'] }
267
+
264
268
  # # FRIENDLY DSL
265
269
 
266
270
  # # A simple DSL is available to allow more user-friendly display of objects. Normally a user object might be shown
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.113
4
+ version: 1.0.115
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-02-17 00:00:00.000000000 Z
11
+ date: 2023-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord