brick 1.0.86 → 1.0.88

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: 67cdd41b9c4a3a235e4d88a151149a7c2c9345a4280efe31c3fbd983b65fbdd4
4
- data.tar.gz: 12f80d33a0360cfa67fb703ed59b65b9216cafa07a18d9283baf9df584067896
3
+ metadata.gz: 9e346878b216d9e54ee0ca15be13ec0c2348f8cdf81d14a1eb4bc24ccb07aadb
4
+ data.tar.gz: 92b54e7227fad318508104690158b5c756cc37171e7eeaaaba41d7da97c5518f
5
5
  SHA512:
6
- metadata.gz: e95aefd208502dfa2ae724d178a29d15ccad4d00522ecbb865019823ba331c0d9f6e4026aea1b634f57f1d7945d8f522e35361d42d9de972698de91c0b9bd129
7
- data.tar.gz: 99d0df87ae591bf836f6040aa237863fb1535774cb6fae515bb1c25edd284b4f37d5a1c01584138df81cfbb66a535ef8bec9aaf2550c96a42c02dee7e48aada1
6
+ metadata.gz: a8797a5e8924e3a89fd958f05d1bd442cf457428257cd697e438e1e6fe93427bc035177cea79fad47c6484427b30d2e3dc778f7a2166bc0fe27d383ce8659c1c
7
+ data.tar.gz: 0bd6d3cc1ad92a1ec897b1524fde2e3f6849c783705312908d206460f9060677c93c295f3f3b89ddd514e2b3d5faeae4900472b0f4a1419e57e91046a190b3f7
@@ -211,7 +211,14 @@ module ActiveRecord
211
211
  this_obj = obj
212
212
  bracket_name.split('.').each do |part|
213
213
  obj_name += ".#{part}"
214
- this_obj = caches.fetch(obj_name) { caches[obj_name] = this_obj&.send(part.to_sym) }
214
+ this_obj = begin
215
+ caches.fetch(obj_name) { caches[obj_name] = this_obj&.send(part.to_sym) }
216
+ rescue
217
+ clsnm = part.camelize
218
+ if (possible = this_obj.class.reflect_on_all_associations.select { |a| a.class_name == clsnm || a.klass.base_class.name == clsnm }.first)
219
+ caches[obj_name] = this_obj&.send(possible.name)
220
+ end
221
+ end
215
222
  break if this_obj.nil?
216
223
  end
217
224
  if this_obj.is_a?(ActiveRecord::Base) && (obj_descrip = this_obj.class.brick_descrip(this_obj))
@@ -834,34 +841,9 @@ if Object.const_defined?('ActionView')
834
841
  args.first) ||
835
842
  @_brick_model
836
843
  # If not provided, do a best-effort to automatically determine the resource class or object
837
- sti_type = nil
838
844
  filter_parts = []
839
845
  klass_or_obj ||= begin
840
- res_names = ::Brick.relations.each_with_object({}) do |v, s|
841
- v_parts = v.first.split('.')
842
- v_parts.shift if v_parts.first == 'public'
843
- s[v_parts.join('.')] = v.first
844
- end
845
- c_path_parts = controller_path.split('/')
846
- klass = nil
847
- while c_path_parts.present?
848
- possible_c_path = c_path_parts.join('.')
849
- possible_c_path_singular = c_path_parts[0..-2] + [c_path_parts.last.singularize]
850
- possible_sti = possible_c_path_singular.join('/').camelize
851
- break if (
852
- res_name = res_names[possible_c_path] ||
853
- ((klass = Brick.config.sti_namespace_prefixes.key?("::#{possible_sti}") && possible_sti.constantize) &&
854
- (sti_type = possible_sti)) ||
855
- # %%% Used to have the more flexible: (DidYouMean::SpellChecker.new(dictionary: res_names.keys).correct(possible_c_path)).first
856
- res_names[possible_c_path] || res_names[possible_c_path_singular.join('.')]
857
- ) &&
858
- (
859
- klass ||
860
- ((rel = ::Brick.relations.fetch(res_name, nil)) &&
861
- (klass ||= rel[:class_name]&.constantize))
862
- )
863
- c_path_parts.shift
864
- end
846
+ klass, sti_type = ::Brick.ctrl_to_klass(controller_path)
865
847
  if klass
866
848
  type_col = klass.inheritance_column # Usually 'type'
867
849
  filter_parts << "#{type_col}=#{sti_type}" if sti_type && klass.column_names.include?(type_col)
@@ -1797,12 +1779,18 @@ end.class_exec do
1797
1779
  # This is done separately so that during testing it can be called right after a migration
1798
1780
  # in order to make sure everything is good.
1799
1781
  def _brick_reflect_tables
1782
+ return unless ::Brick.config.mode == :on
1783
+
1800
1784
  # return if ActiveRecord::Base.connection.current_database == 'postgres'
1801
1785
 
1802
1786
  initializer_loaded = false
1803
1787
  orig_schema = nil
1804
1788
  if (relations = ::Brick.relations).empty?
1805
- # If there's schema things configured then we only expect our initializer to be named exactly this
1789
+ # Very first thing, load inflections since we'll be using .pluralize and .singularize on table and model names
1790
+ if File.exist?(inflections = ::Rails.root.join('config/initializers/inflections.rb'))
1791
+ load inflections
1792
+ end
1793
+ # Now the Brick initializer since there may be important schema things configured
1806
1794
  if File.exist?(brick_initializer = ::Rails.root.join('config/initializers/brick.rb'))
1807
1795
  initializer_loaded = load brick_initializer
1808
1796
  end
@@ -1870,8 +1858,9 @@ end.class_exec do
1870
1858
  ::Brick.db_schemas ||= {}
1871
1859
 
1872
1860
  if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
1873
- if (possible_schema = ::Brick.config.schema_behavior&.[](:multitenant)&.[](:schema_to_analyse))
1874
- if ::Brick.db_schemas.key?(possible_schema)
1861
+ if (possible_schemas = ::Brick.config.schema_behavior&.[](:multitenant)&.[](:schema_to_analyse))
1862
+ possible_schemas = [possible_schemas] unless possible_schemas.is_a?(Array)
1863
+ if (possible_schema = possible_schemas.find { |ps| ::Brick.db_schemas.key?(ps) })
1875
1864
  ::Brick.default_schema = schema = possible_schema
1876
1865
  orig_schema = ActiveRecord::Base.execute_sql('SELECT current_schemas(true)').first['current_schemas'][1..-2].split(',')
1877
1866
  ActiveRecord::Base.execute_sql("SET SEARCH_PATH = ?", schema)
@@ -1881,7 +1870,7 @@ end.class_exec do
1881
1870
  orig_schema = ActiveRecord::Base.execute_sql('SELECT current_schemas(true)').first['current_schemas'][1..-2].split(',')
1882
1871
  ActiveRecord::Base.execute_sql("SET SEARCH_PATH = ?", schema)
1883
1872
  else
1884
- puts "*** In the brick.rb initializer the line \"::Brick.schema_behavior = ...\" refers to a schema called \"#{possible_schema}\". This schema does not exist. ***"
1873
+ puts "*** In the brick.rb initializer the line \"::Brick.schema_behavior = ...\" refers to schema(s) called #{possible_schemas.map { |s| "\"#{s}\"" }.join(', ')}. No mentioned schema exists. ***"
1885
1874
  end
1886
1875
  end
1887
1876
  end
@@ -502,6 +502,16 @@ window.addEventListener(\"pageshow\", function() {
502
502
  }
503
503
  });
504
504
 
505
+ // Add \"Are you sure?\" behaviour to any data-confirm buttons out there
506
+ document.querySelectorAll(\"input[type=submit][data-confirm]\").forEach(function (btn) {
507
+ btn.addEventListener(\"click\", function (evt) {
508
+ if (!confirm(this.getAttribute(\"data-confirm\"))) {
509
+ evt.preventDefault();
510
+ return false;
511
+ }
512
+ });
513
+ });
514
+
505
515
  function changeout(href, param, value, trimAfter) {
506
516
  var hrefParts = href.split(\"?\");
507
517
  var params = hrefParts.length > 1 ? hrefParts[1].split(\"&\") : [];
@@ -556,13 +566,19 @@ if (grid) {
556
566
  if (lastHighCell) lastHighCell.classList.remove(\"highlight\");
557
567
  }
558
568
  var lastHighHeader = gridHighHeader;
559
- gridHighHeader = headerCols[gridHighCell.cellIndex];
560
- if (lastHighHeader !== gridHighHeader) {
569
+ if ((gridHighHeader = headerCols[gridHighCell.cellIndex]) && lastHighHeader !== gridHighHeader) {
561
570
  if (gridHighHeader) gridHighHeader.classList.add(\"highlight\");
562
571
  if (lastHighHeader) lastHighHeader.classList.remove(\"highlight\");
563
572
  }
564
573
  }
565
574
  }
575
+ // // LESS TOUCHY NAVIGATION BACK OR FORWARD IN HISTORY WHEN USING MOUSE WHEEL
576
+ // grid.addEventListener(\"wheel\", function (evt) {
577
+ // grid.scrollLeft += evt.deltaX;
578
+ // document.body.scrollTop += (evt.deltaY * 0.6);
579
+ // evt.preventDefault();
580
+ // return false;
581
+ // });
566
582
  }
567
583
  function setHeaderSizes() {
568
584
  // console.log(\"start\");
@@ -1185,7 +1201,7 @@ end
1185
1201
  <% end %>
1186
1202
 
1187
1203
  #{unless args.first == 'new'
1188
- confirm_are_you_sure = ActionView.version < ::Gem::Version.new('7.0') ? "data: { confirm: 'Are you sure?' }" : "form: { data: { turbo_confirm: 'Are you sure?' } }"
1204
+ confirm_are_you_sure = ActionView.version < ::Gem::Version.new('7.0') ? "data: { confirm: 'Delete #{model_name} -- Are you sure?' }" : "form: { data: { turbo_confirm: 'Delete #{model_name} -- Are you sure?' } }"
1189
1205
  hms_headers.each_with_object(+'') do |hm, s|
1190
1206
  # %%% Would be able to remove this when multiple foreign keys to same destination becomes bulletproof
1191
1207
  next if hm.first.options[:through] && !hm.first.through_reflection
@@ -1250,7 +1266,7 @@ flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
1250
1266
  if (mermaidCode) return; // Cut it short if we've already rendered the diagram
1251
1267
 
1252
1268
  mermaidCode = document.createElement(\"SCRIPT\");
1253
- mermaidCode.setAttribute(\"src\", \"https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js\");
1269
+ mermaidCode.setAttribute(\"src\", \"https://cdn.jsdelivr.net/npm/mermaid@9.1.7/dist/mermaid.min.js\");
1254
1270
  mermaidCode.addEventListener(\"load\", function () {
1255
1271
  mermaid.initialize({
1256
1272
  startOnLoad: true,
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 86
8
+ TINY = 88
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
@@ -563,6 +563,41 @@ In config/initializers/brick.rb appropriate entries would look something like:
563
563
  end
564
564
  puts "\n"
565
565
  end
566
+
567
+ # Attempt to determine an ActiveRecord::Base class and additional STI information when given a controller's path
568
+ def ctrl_to_klass(ctrl_path, res_names = {})
569
+ klass = nil
570
+ sti_type = nil
571
+
572
+ if res_names.empty?
573
+ ::Brick.relations.each_with_object({}) do |v, s|
574
+ v_parts = v.first.split('.')
575
+ v_parts.shift if v_parts.first == 'public'
576
+ res_names[v_parts.join('.')] = v.first
577
+ end
578
+ end
579
+
580
+ c_path_parts = ctrl_path.split('/')
581
+ while c_path_parts.present?
582
+ possible_c_path = c_path_parts.join('.')
583
+ possible_c_path_singular = c_path_parts[0..-2] + [c_path_parts.last.singularize]
584
+ possible_sti = possible_c_path_singular.join('/').camelize
585
+ break if (
586
+ res_name = res_names[possible_c_path] ||
587
+ ((klass = Brick.config.sti_namespace_prefixes.key?("::#{possible_sti}") && possible_sti.constantize) &&
588
+ (sti_type = possible_sti)) ||
589
+ # %%% Used to have the more flexible: (DidYouMean::SpellChecker.new(dictionary: res_names.keys).correct(possible_c_path)).first
590
+ res_names[possible_c_path] || res_names[possible_c_path_singular.join('.')]
591
+ ) &&
592
+ (
593
+ klass ||
594
+ ((rel = ::Brick.relations.fetch(res_name, nil)) &&
595
+ (klass ||= rel[:class_name]&.constantize))
596
+ )
597
+ c_path_parts.shift
598
+ end
599
+ [klass, sti_type]
600
+ end
566
601
  end
567
602
 
568
603
  module RouteSet
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.86
4
+ version: 1.0.88
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-10-27 00:00:00.000000000 Z
11
+ date: 2022-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord