brick 1.0.65 → 1.0.68

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: 8a69a2b2fabbd8850a4484ae743c51ea895329d984638b0d7448a020859163f3
4
- data.tar.gz: 46e5b56d1606aeaa1489b12462c417eabba871eca5cd018c223f915092157e11
3
+ metadata.gz: 977737d8dec8900c82e2a973060dca56ae7897e281557e43e1c0696012521270
4
+ data.tar.gz: 8a005ecab292cbfdaf94b29476d4db56e9f5b71a46a5f71ca6fd049550ed4cff
5
5
  SHA512:
6
- metadata.gz: e4817d2bef72c2e8082eee5762616f72b1e1c360ac395bb79b2272ceffa46849f7da89b72f99044875f70d688970f2529d9d9bb1ddea3b1b3adbe816d608345f
7
- data.tar.gz: c992c1d4979ee36e8eaa4a6d575c5e19defafd926b2c30aa73ea0c2c4c1789f8418431b8e1af7b0832d747c26e2861b91eed070725004746d25255a74d984571
6
+ metadata.gz: c3cfaf5cdcdf67038ba5969306f49b73c09977b9e1dec078ad3ca3d6f6e7d16b5b0d18eb16a982568966ac91cabdcb96e82362cce4906485581b36ce2e2410da
7
+ data.tar.gz: 50f38455e43528478fe694f08bfcc50a8968536c9e4e6d8ab0c1713ff621e2153454a541d8e5940f584f2bd9e06549c4d3db047ac11fbdedaf5bc536d0ac7cd1
@@ -657,9 +657,12 @@ Module.class_exec do
657
657
  full_class_name = +''
658
658
  full_class_name << "::#{self.name}" unless self == Object
659
659
  full_class_name << "::#{plural_class_name.underscore.singularize.camelize}"
660
- if (plural_class_name == 'BrickSwagger' ||
661
- ((::Brick.config.add_status || ::Brick.config.add_orphans) && plural_class_name == 'BrickGem') ||
662
- model = self.const_get(full_class_name))
660
+ if plural_class_name == 'BrickSwagger' ||
661
+ (
662
+ (::Brick.config.add_status || ::Brick.config.add_orphans) &&
663
+ plural_class_name == 'BrickGem'
664
+ ) ||
665
+ model = self.const_get(full_class_name)
663
666
  # if it's a controller and no match or a model doesn't really use the same table name, eager load all models and try to find a model class of the right name.
664
667
  Object.send(:build_controller, self, class_name, plural_class_name, model, relations)
665
668
  end
@@ -1033,7 +1036,7 @@ class Object
1033
1036
  self.define_method :orphans do
1034
1037
  instance_variable_set(:@orphans, ::Brick.find_orphans(::Brick.set_db_schema(params)))
1035
1038
  end
1036
- return [new_controller_class, code + ' # BrickGem controller']
1039
+ return [new_controller_class, code + "end # BrickGem controller\n"]
1037
1040
  when 'BrickSwagger'
1038
1041
  is_swagger = true # if request.format == :json)
1039
1042
  end
@@ -1193,6 +1196,8 @@ class Object
1193
1196
  else
1194
1197
  instance_variable_set("@#{singular_table_name}".to_sym,
1195
1198
  model.send(:create, send(params_name_sym)))
1199
+ index
1200
+ render :index
1196
1201
  end
1197
1202
  end
1198
1203
 
@@ -1353,14 +1358,12 @@ module ActiveRecord::ConnectionHandling
1353
1358
  when 'Mysql2'
1354
1359
  ::Brick.default_schema = schema = ActiveRecord::Base.connection.current_database
1355
1360
  when 'SQLite'
1356
- # %%% Retrieve internal ActiveRecord table names like this:
1357
- # ActiveRecord::Base.internal_metadata_table_name, ActiveRecord::Base.schema_migrations_table_name
1358
1361
  sql = "SELECT m.name AS relation_name, UPPER(m.type) AS table_type,
1359
1362
  p.name AS column_name, p.type AS data_type,
1360
1363
  CASE p.pk WHEN 1 THEN 'PRIMARY KEY' END AS const
1361
1364
  FROM sqlite_master AS m
1362
1365
  INNER JOIN pragma_table_info(m.name) AS p
1363
- WHERE m.name NOT IN (?, ?)
1366
+ WHERE m.name NOT IN ('sqlite_sequence', ?, ?)
1364
1367
  ORDER BY m.name, p.cid"
1365
1368
  else
1366
1369
  puts "Unfamiliar with connection adapter #{ActiveRecord::Base.connection.adapter_name}"
@@ -96,16 +96,15 @@ module Brick
96
96
 
97
97
  alias :_brick_find_template :find_template
98
98
  def find_template(*args, **options)
99
- unless (model_name = (
100
- @_brick_model ||
101
- (ActionView.version < ::Gem::Version.new('5.0') && args[1].is_a?(Array) ? set_brick_model(args) : nil)
102
- )&.name) ||
99
+ unless (model_name = @_brick_model&.name) ||
103
100
  (is_status = ::Brick.config.add_status && args[0..1] == ['status', ['brick_gem']]) ||
104
- (is_orphans = ::Brick.config.add_orphans && args[0..1] == ['orphans', ['brick_gem']])
101
+ (is_orphans = ::Brick.config.add_orphans && args[0..1] == ['orphans', ['brick_gem']]) ||
102
+ # Used to also have: ActionView.version < ::Gem::Version.new('5.0') &&
103
+ (model_name = (args[1].is_a?(Array) ? set_brick_model(args) : nil)&.name)
105
104
  return _brick_find_template(*args, **options)
106
105
  end
107
106
 
108
- unless is_status || is_orphans
107
+ if @_brick_model
109
108
  pk = @_brick_model._brick_primary_key(::Brick.relations.fetch(model_name, nil))
110
109
  obj_name = model_name.split('::').last.underscore
111
110
  path_obj_name = model_name.underscore.tr('/', '_')
@@ -156,7 +155,7 @@ module Brick
156
155
  end
157
156
  hm_entry << ']'
158
157
  hms_columns << hm_entry
159
- when 'show', 'update'
158
+ when 'show', 'new', 'update'
160
159
  hm_stuff << if hm_fk_name
161
160
  "<%= link_to '#{assoc_name}', #{hm_assoc.klass.name.underscore.tr('/', '_').pluralize}_path({ #{path_keys(hm_assoc, hm_fk_name, "@#{obj_name}", pk)} }) %>\n"
162
161
  else # %%% Would be able to remove this when multiple foreign keys to same destination becomes bulletproof
@@ -179,6 +178,7 @@ module Brick
179
178
  end.keys.sort.each_with_object(+'') do |v, s|
180
179
  s << "<option value=\"#{v.underscore.gsub('.', '/').pluralize}\">#{v}</option>"
181
180
  end.html_safe
181
+ table_options << '<option value="brick_status">(Status)</option>'.html_safe if ::Brick.config.add_status
182
182
  table_options << '<option value="brick_orphans">(Orphans)</option>'.html_safe if is_orphans
183
183
  css = +"<style>
184
184
  h1, h3 {
@@ -275,7 +275,7 @@ tr th, tr td {
275
275
  color: #80B8D2;
276
276
  }
277
277
 
278
- table.shadow tbody tr {
278
+ table.shadow > tbody > tr {
279
279
  border-bottom: thin solid #dddddd;
280
280
  }
281
281
 
@@ -283,7 +283,7 @@ table tbody tr:nth-of-type(even) {
283
283
  background-color: #f3f3f3;
284
284
  }
285
285
 
286
- table.shadow tbody tr:last-of-type {
286
+ table.shadow > tbody > tr:last-of-type {
287
287
  border-bottom: 2px solid #009879;
288
288
  }
289
289
 
@@ -300,14 +300,6 @@ a.big-arrow {
300
300
  font-size: 2.5em;
301
301
  text-decoration: none;
302
302
  }
303
- .wide-input {
304
- display: block;
305
- overflow: hidden;
306
- }
307
- .wide-input input[type=text] {
308
- display: inline-block;
309
- width: 90%;
310
- }
311
303
  .dimmed {
312
304
  background-color: #C0C0C0;
313
305
  text-align: center;
@@ -324,9 +316,6 @@ svg.revert {
324
316
  display: none;
325
317
  margin-left: 0.25em;
326
318
  }
327
- .wide-input > svg.revert {
328
- float: right;
329
- }
330
319
  input+svg.revert {
331
320
  top: 0.5em;
332
321
  }
@@ -365,8 +354,8 @@ def display_value(col_type, val)
365
354
  @is_mysql = ActiveRecord::Base.connection.adapter_name == 'Mysql2' if @is_mysql.nil?
366
355
  if @is_mysql
367
356
  # MySQL's \"Internal Geometry Format\" is like WKB, but with an initial 4 bytes that indicates the SRID.
368
- srid = val[..3].unpack('I')
369
- val = val[4..]
357
+ srid = val[0..3].unpack('I')
358
+ val = val[4..-1]
370
359
  end
371
360
  RGeo::WKRep::WKBParser.new.parse(val)
372
361
  else
@@ -379,9 +368,10 @@ def display_value(col_type, val)
379
368
  '?'
380
369
  end
381
370
  end
382
- end %>"
371
+ end
372
+ callbacks = {} %>"
383
373
 
384
- if ['index', 'show', 'update'].include?(args.first)
374
+ if ['index', 'show', 'new', 'update'].include?(args.first)
385
375
  poly_cols = []
386
376
  css << "<% bts = { #{
387
377
  bt_items = bts.each_with_object([]) do |v, s|
@@ -537,17 +527,18 @@ if (headerTop) {
537
527
  }
538
528
  </script>"
539
529
 
540
- erd_markup = "<div id=\"mermaidErd\" class=\"mermaid\">
530
+ erd_markup = if @_brick_model
531
+ "<div id=\"mermaidErd\" class=\"mermaid\">
541
532
  erDiagram
542
533
  <% model_short_name = #{@_brick_model.name.split('::').last.inspect}
543
- callbacks = {}
544
534
  @_brick_bt_descrip&.each do |bt|
545
535
  bt_class = bt[1].first.first
546
536
  callbacks[bt_name = bt_class.name.split('::').last] = bt_class
547
537
  is_has_one = #{@_brick_model.name}.reflect_on_association(bt.first).inverse_of&.macro == :has_one ||
548
538
  ::Brick.config.has_ones&.fetch('#{@_brick_model.name}', nil)&.key?(bt.first.to_s)
549
539
  %> <%= \"#\{model_short_name} #\{is_has_one ? '||' : '}o'}--|| #\{bt_name} : \\\"#\{
550
- bt.first unless bt.first.to_s == bt[1].first.first.name.underscore.singularize.tr('/', '_')
540
+ bt_underscored = bt[1].first.first.name.underscore.singularize
541
+ bt.first unless bt.first.to_s == bt_underscored.split('/').last # Was: bt_underscored.tr('/', '_')
551
542
  }\\\"\".html_safe %>
552
543
  <% end
553
544
  last_through = nil
@@ -557,14 +548,15 @@ erDiagram
557
548
 
558
549
  callbacks[hm_name = hm_class.name.split('::').last] = hm_class
559
550
  if (through = hm.last.options[:through]&.to_s) # has_many :through (HMT)
560
- callbacks[through.singularize.camelize] = (through_assoc = hm.last.source_reflection).active_record
551
+ through_name = (through_assoc = hm.last.source_reflection).active_record.name.split('::').last
552
+ callbacks[through_name] = through_assoc.active_record
561
553
  if last_through == through # Same HM, so no need to build it again, and for clarity just put in a blank line
562
554
  %><%= \"\n\"
563
555
  %><% else
564
- %> <%= \"#\{model_short_name} ||--o{ #\{through_assoc.active_record.name}\".html_safe %> : \"\"
556
+ %> <%= \"#\{model_short_name} ||--o{ #\{through_name}\".html_safe %> : \"\"
565
557
  <% last_through = through
566
558
  end
567
- %> <%= \"#\{through_assoc.active_record.name} }o--|| #\{hm_name}\".html_safe %> : \"\"
559
+ %> <%= \"#\{through_name} }o--|| #\{hm_name}\".html_safe %> : \"\"
568
560
  <%= \"#\{model_short_name} }o..o{ #\{hm_name} : \\\"#\{hm.first}\\\"\".html_safe %><%
569
561
  else # has_many
570
562
  %> <%= \"#\{model_short_name} ||--o{ #\{hm_name} : \\\"#\{
@@ -572,21 +564,25 @@ erDiagram
572
564
  }\\\"\".html_safe %><%
573
565
  end %>
574
566
  <% end
567
+ def dt_lookup(dt)
568
+ { 'integer' => 'int', }[dt] || dt.tr(' ', '_')
569
+ end
575
570
  callbacks.merge({model_short_name => #{@_brick_model.name}}).each do |cb_k, cb_class|
576
571
  cb_relation = ::Brick.relations[cb_class.table_name]
577
572
  pkeys = cb_relation[:pkey]&.first&.last
578
573
  fkeys = cb_relation[:fks]&.values&.each_with_object([]) { |fk, s| s << fk[:fk] if fk.fetch(:is_bt, nil) }
574
+ cols = cb_relation[:cols]
579
575
  %> <%= cb_k %> {<%
580
576
  pkeys&.each do |pk| %>
581
- <%= \"int #\{pk} \\\"PK#\{' fk' if fkeys&.include?(pk)}\\\"\".html_safe %><%
577
+ <%= \"#\{dt_lookup(cols[pk].first)} #\{pk} \\\"PK#\{' fk' if fkeys&.include?(pk)}\\\"\".html_safe %><%
582
578
  end %><%
583
579
  fkeys&.each do |fk|
584
580
  if fk.is_a?(Array)
585
581
  fk.each do |fk_part| %>
586
- <%= \"int #\{fk_part} \\\"&nbsp;&nbsp;&nbsp;&nbsp;fk\\\"\".html_safe unless pkeys&.include?(fk_part) %><%
582
+ <%= \"#\{dt_lookup(cols[fk_part].first)} #\{fk_part} \\\"&nbsp;&nbsp;&nbsp;&nbsp;fk\\\"\".html_safe unless pkeys&.include?(fk_part) %><%
587
583
  end
588
584
  else %>
589
- <%= \"int #\{fk} \\\"&nbsp;&nbsp;&nbsp;&nbsp;fk\\\"\".html_safe unless pkeys&.include?(fk) %><%
585
+ <%= \"#\{dt_lookup(cols[fk].first)} #\{fk} \\\"&nbsp;&nbsp;&nbsp;&nbsp;fk\\\"\".html_safe unless pkeys&.include?(fk) %><%
590
586
  end
591
587
  end %>
592
588
  }
@@ -595,6 +591,7 @@ erDiagram
595
591
  %>
596
592
  </div>
597
593
  "
594
+ end
598
595
  inline = case args.first
599
596
  when 'index'
600
597
  obj_pk = if pk&.is_a?(Array) # Composite primary key?
@@ -690,7 +687,7 @@ erDiagram
690
687
  </script>
691
688
  <script async defer src=\"https://apis.google.com/js/api.js\" onload=\"gapiLoaded()\"></script>
692
689
  "
693
- end
690
+ end # DutyFree data export and import
694
691
  # %%% Instead of our current "for Janet Leverling (Employee)" kind of link we previously had this code that did a "where x = 123" thing:
695
692
  # (where <%= @_brick_params.each_with_object([]) { |v, s| s << \"#\{v.first\} = #\{v.last.inspect\}\" }.join(', ') %>)
696
693
  +"#{css}
@@ -829,6 +826,7 @@ erDiagram
829
826
  #{script}"
830
827
 
831
828
  when 'status'
829
+ if is_status
832
830
  # Status page - list of all resources and 5 things they do or don't have present, and what is turned on and off
833
831
  # Must load all models, and then find what table names are represented
834
832
  # Easily could be multiple files involved (STI for instance)
@@ -852,7 +850,7 @@ erDiagram
852
850
  @resources.each do |r|
853
851
  %>
854
852
  <tr>
855
- <td><%= link_to(r[0], \"/#\{r[0].tr('.', '/')}\") %></td>
853
+ <td><%= link_to(r[0], \"/#\{r[0].underscore.tr('.', '/')}\") %></td>
856
854
  <td<%= if r[1]
857
855
  ' class=\"orphan\"' unless ::Brick.relations.key?(r[1])
858
856
  else
@@ -873,6 +871,7 @@ erDiagram
873
871
  <% end %>
874
872
  </tbody></table>
875
873
  #{script}"
874
+ end
876
875
 
877
876
  when 'orphans'
878
877
  if is_orphans
@@ -890,7 +889,7 @@ erDiagram
890
889
  #{script}"
891
890
  end
892
891
 
893
- when 'show', 'update'
892
+ when 'show', 'new', 'update'
894
893
  +"#{css}
895
894
 
896
895
  <svg id=\"revertTemplate\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"
@@ -958,38 +957,41 @@ end
958
957
  <% end %>
959
958
  </th>
960
959
  <td>
960
+ <table><tr><td>
961
961
  <% dt_pickers = { datetime: 'datetimepicker', timestamp: 'datetimepicker', time: 'timepicker', date: 'datepicker' }
962
+ html_options = {}
963
+ html_options[:class] = 'dimmed' unless val
964
+ is_revert = true
962
965
  if bt
963
- html_options = { prompt: \"Select #\{bt_name\}\" }
964
- html_options[:class] = 'dimmed' unless val %>
966
+ html_options[:prompt] = \"Select #\{bt_name\}\" %>
965
967
  <%= f.select k.to_sym, bt[3], { value: val || '^^^brick_NULL^^^' }, html_options %>
966
968
  <%= if (bt_obj = bt_class&.find_by(bt_pair[1] => val))
967
969
  link_to('⇛', send(\"#\{bt_class.base_class.name.underscore.tr('/', '_')\}_path\".to_sym, bt_obj.send(bt_class.primary_key.to_sym)), { class: 'show-arrow' })
968
970
  elsif val
969
971
  \"<span class=\\\"orphan\\\">Orphaned ID: #\{val}</span>\".html_safe
970
- end %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
972
+ end %>
971
973
  <% else
972
- html_options = {}
973
- html_options[:class] = 'dimmed' unless val
974
- case (col_type = col.type || col.sql_type)
974
+ case (col_type = col.type || col.sql_type)
975
975
  when :string, :text %>
976
- <% if is_bcrypt?(val) # || .readonly? %>
976
+ <% if is_bcrypt?(val) # || .readonly?
977
+ is_revert = false %>
977
978
  <%= hide_bcrypt(val, 1000) %>
978
979
  <% else %>
979
- <div class=\"wide-input\"><%= f.text_field(k.to_sym, html_options) %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg></div>
980
+ <%= f.text_field(k.to_sym, html_options) %>
980
981
  <% end %>
981
982
  <% when :boolean %>
982
- <%= f.check_box k.to_sym %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
983
+ <%= f.check_box k.to_sym %>
983
984
  <% when :integer, :decimal, :float %>
984
985
  <%= if col_type == :integer
985
986
  f.text_field k.to_sym, { pattern: '\\d*', class: 'check-validity' }
986
987
  else
987
988
  f.number_field k.to_sym
988
- end %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
989
+ end %>
989
990
  <% when *dt_pickers.keys
990
991
  is_includes_dates = true %>
991
- <%= f.text_field k.to_sym, { class: dt_pickers[col_type] } %><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
992
- <% when :uuid %>
992
+ <%= f.text_field k.to_sym, { class: dt_pickers[col_type] } %>
993
+ <% when :uuid
994
+ is_revert = false %>
993
995
  <%=
994
996
  # Postgres naturally uses the +uuid_generate_v4()+ function from the uuid-ossp extension
995
997
  # If it's not yet enabled then: create extension \"uuid-ossp\";
@@ -1000,11 +1002,18 @@ end
1000
1002
  # In Postgres labels of data stored in a hierarchical tree-like structure
1001
1003
  # If it's not yet enabled then: create extension ltree;
1002
1004
  val %>
1003
- <% when :binary, :primary_key %>
1005
+ <% when :binary, :primary_key
1006
+ is_revert = false %>
1004
1007
  <% else %>
1005
- <%= display_value(col_type, val) %>
1008
+ <%= display_value(col_type, val)
1009
+ is_revert = false %>
1010
+ <% end
1011
+ end
1012
+ if is_revert
1013
+ %></td>
1014
+ <td><svg class=\"revert\" width=\"1.5em\" viewBox=\"0 0 512 512\"><use xlink:href=\"#revertPath\" /></svg>
1006
1015
  <% end %>
1007
- <% end %>
1016
+ </td></tr></table>
1008
1017
  </td>
1009
1018
  </tr>
1010
1019
  <% end
@@ -1066,7 +1075,7 @@ flatpickr(\".timepicker\", {enableTime: true, noCalendar: true});
1066
1075
  var mermaidErd = document.getElementById(\"mermaidErd\");
1067
1076
  var mermaidCode;
1068
1077
  var cbs = {<%= callbacks.map { |k, v| \"#\{k}: \\\"#\{v.name.underscore.pluralize}\\\"\" }.join(', ').html_safe %>};
1069
- imgErd.addEventListener(\"click\", showErd);
1078
+ if (imgErd) imgErd.addEventListener(\"click\", showErd);
1070
1079
  function showErd() {
1071
1080
  imgErd.style.display = \"none\";
1072
1081
  mermaidErd.style.display = \"inline-block\";
@@ -1127,9 +1136,12 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1127
1136
  var origVal = getInpVal(),
1128
1137
  prevVal = origVal;
1129
1138
  var revert;
1130
- if ((revert = ((inp.tagName === \"SELECT\" && inp.nextElementSibling.nextElementSibling) ||
1131
- inp.nextElementSibling ||
1132
- inp.parentElement.nextElementSibling)) && revert.tagName.toLowerCase() === \"svg\")
1139
+ if (inp.getAttribute(\"type\") == \"hidden\" || inp.getAttribute(\"type\") == \"submit\") return;
1140
+
1141
+ var svgTd = null;
1142
+ if ((revert = ((inp.tagName === \"SELECT\" && (svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild) ||
1143
+ ((svgTd = inp.parentElement.nextElementSibling) && svgTd.firstElementChild))
1144
+ ) && revert.tagName.toLowerCase() === \"svg\")
1133
1145
  revert.addEventListener(\"click\", function (e) {
1134
1146
  if (inp.type === \"checkbox\")
1135
1147
  inp.checked = origVal;
@@ -1160,7 +1172,7 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1160
1172
  prevVal = getInpVal();
1161
1173
  }
1162
1174
  // Show or hide the revert button
1163
- if (revert) revert.style.display = getInpVal() === origVal ? \"none\" : \"inline-block\";
1175
+ if (revert) revert.style.display = getInpVal() === origVal ? \"none\" : \"block\";
1164
1176
  });
1165
1177
  function getInpVal() {
1166
1178
  return inp.type === \"checkbox\" ? inp.checked : inp.value;
@@ -1180,6 +1192,13 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) {
1180
1192
  # In order to defer auto-creation of any routes that already exist, calculate Brick routes only after having loaded all others
1181
1193
  prepend ::Brick::RouteSet
1182
1194
  end
1195
+ # Do the root route before the Rails Welcome one would otherwise take precedence
1196
+ unless (route = ::Brick.config.default_route_fallback).blank? ||
1197
+ ::Rails.application.routes.named_routes.send(:routes)[:root]
1198
+ ::Rails.application.routes.append do
1199
+ send(:root, "#{route}#{'#index' unless route.index('#')}")
1200
+ end
1201
+ end
1183
1202
  end
1184
1203
 
1185
1204
  # Just in case it hadn't been done previously when we tried to load the brick initialiser,
@@ -5,7 +5,7 @@ module Brick
5
5
  module VERSION
6
6
  MAJOR = 1
7
7
  MINOR = 0
8
- TINY = 65
8
+ TINY = 68
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
@@ -123,7 +123,7 @@ module Brick
123
123
  end
124
124
 
125
125
  class << self
126
- attr_accessor :default_schema, :db_schemas
126
+ attr_accessor :default_schema, :db_schemas, :routes_done
127
127
 
128
128
  def set_db_schema(params)
129
129
  schema = params['_brick_schema'] || 'public'
@@ -461,11 +461,11 @@ In config/initializers/brick.rb appropriate entries would look something like:
461
461
 
462
462
  module RouteSet
463
463
  def finalize!
464
+ return super if ::Brick.routes_done
465
+
466
+ ::Brick.routes_done = true
464
467
  existing_controllers = routes.each_with_object({}) { |r, s| c = r.defaults[:controller]; s[c] = nil if c }
465
468
  ::Rails.application.routes.append do
466
- unless ::Brick.config.default_route_fallback.blank? || ::Rails.application.routes.named_routes.send(:routes)[:root]
467
- send(:root, "#{::Brick.config.default_route_fallback}#index")
468
- end
469
469
  # %%% TODO: If no auto-controllers then enumerate the controllers folder in order to build matching routes
470
470
  # If auto-controllers and auto-models are both enabled then this makes sense:
471
471
  ::Brick.relations.each do |rel_name, v|
@@ -279,8 +279,8 @@ module Brick
279
279
  # # route to go to the :index action for what would be a controller for that table. You can specify any controller
280
280
  # # name and action you wish in order to override this and have that be the default route when none other has been
281
281
  # # specified in routes.rb or elsewhere. (Or just use an empty string in order to disable this behaviour.)
282
- # Brick.default_route_fallback = 'customers' # This defaults to \"customers/index\"
283
- # Brick.default_route_fallback = 'orders/outstanding' # Example of a non-RESTful route
282
+ # Brick.default_route_fallback = 'customers' # This defaults to \"customers#index\"
283
+ # Brick.default_route_fallback = 'orders#outstanding' # Example of a non-RESTful route
284
284
  # Brick.default_route_fallback = '' # Omits setting a default route in the absence of any other
285
285
  ")
286
286
  end
@@ -22,7 +22,16 @@ module Brick
22
22
  'time without time zone' => 'time',
23
23
  'time with time zone' => 'time',
24
24
  'double precision' => 'float',
25
- 'smallint' => 'integer' } # %%% Need to put in "limit: 2"
25
+ 'smallint' => 'integer', # %%% Need to put in "limit: 2"
26
+ # Sqlite data types
27
+ 'TEXT' => 'text',
28
+ '' => 'string',
29
+ 'INTEGER' => 'integer',
30
+ 'REAL' => 'float',
31
+ 'BLOB' => 'binary',
32
+ 'TIMESTAMP' => 'timestamp',
33
+ 'DATETIME' => 'timestamp'
34
+ }
26
35
  # (Still need to find what "inet" and "json" data types map to.)
27
36
 
28
37
  desc 'Auto-generates migration files for an existing database.'
@@ -38,7 +47,8 @@ module Brick
38
47
  return
39
48
  end
40
49
 
41
- key_type = (ActiveRecord.version < ::Gem::Version.new('5.1') ? 'integer' : 'bigint')
50
+ is_sqlite = ActiveRecord::Base.connection.adapter_name == 'SQLite'
51
+ key_type = ((is_sqlite || ActiveRecord.version < ::Gem::Version.new('5.1')) ? 'integer' : 'bigint')
42
52
  is_4x_rails = ActiveRecord.version < ::Gem::Version.new('5.0')
43
53
  ar_version = "[#{ActiveRecord.version.segments[0..1].join('.')}]" unless is_4x_rails
44
54
  is_insert_versions = true
@@ -142,21 +152,20 @@ module Brick
142
152
  # if this one has come in as bigint or integer.
143
153
  pk_is_also_fk = fkey_cols.any? { |assoc| pkey_cols&.first == assoc[:fk] } ? pkey_cols&.first : nil
144
154
  # Support missing primary key (by adding: ,id: false)
145
- id_option = if pk_is_also_fk || (pkey_col_first = relation[:cols][pkey_cols&.first]&.first) != key_type
146
- if pk_is_also_fk || !pkey_cols&.present?
147
- ', id: false'
155
+ id_option = if pk_is_also_fk || !pkey_cols&.present?
156
+ ', id: false'
157
+ elsif ((pkey_col_first = relation[:cols][pkey_cols&.first]&.first) &&
158
+ (pkey_col_first = SQL_TYPES[pkey_col_first] || pkey_col_first) != key_type)
159
+ case pkey_col_first
160
+ when 'integer'
161
+ ', id: :serial'
162
+ when 'bigint'
163
+ ', id: :bigserial'
148
164
  else
149
- case pkey_col_first
150
- when 'integer'
151
- ', id: :serial'
152
- when 'bigint'
153
- ', id: :bigserial'
154
- else
155
- ", id: :#{SQL_TYPES[pkey_col_first] || pkey_col_first}" # Something like: id: :integer, primary_key: :businessentityid
156
- end +
157
- (pkey_cols.first ? ", primary_key: :#{pkey_cols.first}" : '') +
158
- (!is_4x_rails && (comment = relation&.fetch(:description, nil))&.present? ? ", comment: #{comment.inspect}" : '')
159
- end
165
+ ", id: :#{pkey_col_first}" # Something like: id: :integer, primary_key: :businessentityid
166
+ end +
167
+ (pkey_cols.first ? ", primary_key: :#{pkey_cols.first}" : '') +
168
+ (!is_4x_rails && (comment = relation&.fetch(:description, nil))&.present? ? ", comment: #{comment.inspect}" : '')
160
169
  end
161
170
  # Find the ActiveRecord class in order to see if the columns have comments
162
171
  unless is_4x_rails
@@ -208,7 +217,7 @@ module Brick
208
217
  mig << " t.references :#{fk[:assoc_name]}#{suffix}, foreign_key: { to_table: #{to_table} }\n"
209
218
  end
210
219
  else
211
- next if !id_option&.end_with?('id: false') && pkey_cols.include?(col)
220
+ next if !id_option&.end_with?('id: false') && pkey_cols&.include?(col)
212
221
 
213
222
  # See if there are generic timestamps
214
223
  if sql_type == 'timestamp' && ['created_at','updated_at'].include?(col)
@@ -244,7 +253,7 @@ module Brick
244
253
  mig << " #{'# ' if is_commented}add_foreign_key #{tbl_code}, #{add_fk[0]}, column: :#{add_fk[1]}, primary_key: :#{pk}\n"
245
254
  end
246
255
  mig << " end\n"
247
- versions_to_create << migration_file_write(mig_path, "create_#{tbl_parts.join('_')}", current_mig_time += 1.minute, ar_version, mig)
256
+ versions_to_create << migration_file_write(mig_path, "create_#{tbl_parts.map(&:underscore).join('_')}", current_mig_time += 1.minute, ar_version, mig)
248
257
  end
249
258
  done.concat(fringe)
250
259
  chosen -= done
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.65
4
+ version: 1.0.68
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-08-29 00:00:00.000000000 Z
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord